- name: Make zerod swap file command: dd if=/dev/zero of={{ swap_file.path }} bs=1024 count={{swap_file.size_kb}} creates={{ swap_file.path }} - name: Set swap permissions file: path={{ swap_file.path }} owner=root group=root mode=0600 - name: Check swap type command: file {{ swap_file.path }} register: swapfile_info changed_when: swapfile_info.stdout.find('swap file') == -1 - name: mkswap on swap file command: mkswap {{ swap_file.path }} when: swapfile_info.stdout.find('swap file') == -1 - name: Put the swap entry into fstab mount: name=none src={{ swap_file.path }} fstype=swap opts=sw passno=0 dump=0 state=present - name: Swapon swapfile command: swapon {{ swap_file.path }} when: ansible_swaptotal_mb < 1