diff --git a/requirements.yml b/requirements.yml index 3d5f1cd..947188a 100644 --- a/requirements.yml +++ b/requirements.yml @@ -1,3 +1,4 @@ # requirements file --- -collections: [] +collections: + - name: ansible.posix diff --git a/tasks/main.yml b/tasks/main.yml index 5325d18..c86e990 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,7 +1,7 @@ # tasks file --- - name: install dependencies - apt: + ansible.builtin.apt: name: "{{ swapfile_dependencies }}" state: "{{ apt_install_state | default('latest') }}" update_cache: true @@ -12,10 +12,15 @@ - swapfile-install - swapfile-install-dependencies -- block: - +- name: swap file + # TODO: Changing this to `when: swapfile_size` seems to fail, find out why + when: swapfile_size != false + tags: + - configuration + - swapfile + block: - name: write swap file # noqa command-instead-of-module - command: > + ansible.builtin.command: > fallocate -l {{ swapfile_size }} {{ swapfile_file }} args: creates: "{{ swapfile_file }}" @@ -24,7 +29,7 @@ - swapfile-write-file - name: set swap file permissions - file: + ansible.builtin.file: path: "{{ swapfile_file }}" owner: root group: root @@ -33,22 +38,22 @@ - swapfile-set-file-permissions - name: create swap file # noqa command-instead-of-module - command: > + ansible.builtin.command: > mkswap {{ swapfile_file }} register: _create_swapfile - when: _write_swapfile.changed + when: _write_swapfile is changed tags: - swapfile-mkswap - name: enable swapfile # noqa command-instead-of-module - command: > + ansible.builtin.command: > swapon {{ swapfile_file }} when: _create_swapfile is changed tags: - swapfile-enable-swapfile - name: add swapfile to /etc/fstab - mount: + ansible.posix.mount: name: none src: "{{ swapfile_file }}" fstype: swap @@ -59,14 +64,8 @@ tags: - swapfile-fstab - # TODO: Changing this to `when: swapfile_size` seems to fail, find out why - when: swapfile_size != false - tags: - - configuration - - swapfile - - name: configure vm.swappiness - sysctl: + ansible.posix.sysctl: name: vm.swappiness value: "{{ swapfile_swappiness | string }}" reload: true @@ -78,7 +77,7 @@ - swapfile-vm-swappiness - name: configure vm.vfs_cache_pressure - sysctl: + ansible.posix.sysctl: name: vm.vfs_cache_pressure value: "{{ swapfile_vfs_cache_pressure | string }}" reload: true