--- - name: "Manage swap file entry in fstab" ansible.posix.mount: name: none src: "{{ swapfile_path }}" fstype: swap opts: sw state: "{{ swapfile_state }}" - name: "Include disable swap tasks" when: swapfile_state == 'absent' ansible.builtin.include_tasks: disable.yml - name: "Include enable swap tasks" when: swapfile_state == 'present' ansible.builtin.include_tasks: enable.yml