--- - name: Create swap file ansible.builtin.command: "fallocate -l {{ swap_size }}M {{ swap_path }}" changed_when: False when: swap_size | int > (ansible_swaptotal_mb | int) + 1 - name: Format swap file ansible.builtin.command: "mkswap {{ swap_path }}" changed_when: False when: swap_size | int > (ansible_swaptotal_mb | int) + 1 - name: Fix file permissions ansible.builtin.file: path: "{{ swap_path }}" owner: root group: root mode: "0600" - name: Mount swap file ansible.posix.mount: src: "{{ swap_path }}" path: none fstype: swap state: present - name: Enable swap ansible.builtin.command: "swapon -a" changed_when: False