diff --git a/defaults/main.yml b/defaults/main.yml index 67683ad..eca17a1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -49,6 +49,9 @@ additional_disks: false disks_and_mountpoints_list: [] # - { mountpoint: '/data', device: 'xvda3', fstype: 'xfs', opts: 'noatime', state: 'mounted', create_filesystem: True } +swap_device: false +swap_device_name: /dev/vdxxxxx + ansible_python3_debs: - python3-lxml diff --git a/tasks/main.yml b/tasks/main.yml index 2736145..f22b889 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -23,9 +23,12 @@ - mkcert_create_certificate - name: HTTP client proxy ansible.builtin.import_tasks: http_client_proxy.yml -- name: Manage additiondal disk volumes +- name: Manage additional disk volumes ansible.builtin.import_tasks: additional_disks.yml when: additional_disks +- name: Manage a swap device + ansible.builtin.import_tasks: swap_device.yml + when: swap_device - name: Manage the autofs configuration ansible.builtin.import_tasks: autofs.yml when: autofs_client_mountpoint diff --git a/tasks/swap_device.yml b/tasks/swap_device.yml new file mode 100644 index 0000000..80a7e49 --- /dev/null +++ b/tasks/swap_device.yml @@ -0,0 +1,22 @@ +--- +- name: swap_device | Configure and enable a swap device + when: swap_device + tags: + - swap + - swap_device + block: + - name: swap_device | Initialize the swap device + ansible.builtin.command: mkswap {{ swap_device_name }} && touch /root/.mkswap_executed + args: + creates: /root/.mkswap_executed + register: mkswap_command_execution + - name: swap_device | Enable the swap device + ansible.builtin.command: swapon {{ swap_device_name }} && touch /root/.swapon_executed + args: + creates: /root/.swapon_executed + + - name: swap_device | Add the swap device to the fstab file + ansible.builtin.lineinfile: + path: /etc/fstab + regexp: "^{{ swap_device_name }}" + line: "{{ swap_device_name }} swap swap defaults 0 0"