Optionally setup a swap device.

This commit is contained in:
Andrea Dell'Amico 2024-07-12 16:30:36 +02:00
parent 9f51bcbba2
commit 9244f93dc3
Signed by: adellam
GPG Key ID: 147ABE6CEB9E20FF
3 changed files with 29 additions and 1 deletions

View File

@ -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

View File

@ -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

22
tasks/swap_device.yml Normal file
View File

@ -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"