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