Add swap file to instance

This commit is contained in:
Erik Stambaugh 2024-01-20 09:12:03 -08:00
parent 8bb29eed19
commit 4ec9a020a1
2 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
swap_file_path: "/swapfile"
swap_file_size_mb: '512'

View file

@ -65,3 +65,42 @@
block: | block: |
alias ls='ls --color=auto' alias ls='ls --color=auto'
## set up swap
- name: create swap file
command: "dd if=/dev/zero of={{ swap_file_path }} bs=1024 count={{ swap_file_size_mb }}k"
args:
creates: "{{ swap_file_path }}"
- name: 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: mkswap
command: "mkswap {{ swap_file_path }}"
when: swapfile.stdout.find('swap file') == -1
- name: swapfile 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