swap.yml 871 B

123456789101112131415161718192021222324252627
  1. ---
  2. - name: Create swap file
  3. command: dd if=/dev/zero of={{ swap_file_path }} bs=1024 count={{ swap_file_size_kb }}k creates={{ swap_file_path }}
  4. - name: Change swap file permissions
  5. file: path={{ swap_file_path }} owner=root group=root mode=0600
  6. - name: Check swap file type
  7. command: file {{ swap_file_path }}
  8. register: swapfile
  9. - name: Make swap file
  10. command: mkswap {{ swap_file_path }}
  11. when: swapfile.stdout.find('swap file') == -1
  12. - name: Write swap entry in fstab
  13. mount: name=none src={{ swap_file_path }} fstype=swap opts=sw passno=0 dump=0 state=present
  14. - name: Mount swap
  15. command: swapon {{ swap_file_path }}
  16. when: ansible_swaptotal_mb < 1
  17. - name: Set swapiness in /proc/sys/vm/swappiness
  18. shell: echo 10 | tee /proc/sys/vm/swappiness
  19. - name: Set swapiness in /etc/sysctl.conf
  20. shell: echo vm.swappiness = 10 | tee -a /etc/sysctl.conf