Add swap file to instance
This commit is contained in:
parent
8bb29eed19
commit
4ec9a020a1
2 changed files with 42 additions and 0 deletions
3
ansible/roles/common/defaults/main.yaml
Normal file
3
ansible/roles/common/defaults/main.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
swap_file_path: "/swapfile"
|
||||||
|
swap_file_size_mb: '512'
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue