-
Notifications
You must be signed in to change notification settings - Fork 0
/
swapfile.yml
56 lines (47 loc) · 1.38 KB
/
swapfile.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
- hosts: all
become: true
# Thanks https://github.com/Oefenweb/ansible-swapfile
vars:
swapfile_file: /swapfile
swapfile_size: 1G
swapfile_swappiness: 10
tasks:
- name: SWAP | install dependencies(debian)
apt: name="util-linux" state="present"
when: ansible_os_family == 'Debian'
- name: SWAP | install dependencies(CentOS)
yum: name="util-linux" state="present"
when: ansible_distribution == 'CentOS'
- name: SWAP | create swap file
command: fallocate -l {{ swapfile_size }} {{ swapfile_file }}
register: _create_swapfile
- name: SWAP | set swap file permissions
file:
path: "{{ swapfile_file }}"
owner: root
group: root
mode: 0600
- name: SWAP | mkswap
command: mkswap {{ swapfile_file }}
register: created
when: _create_swapfile.changed
- name: SWAP | enable swapfile
command: swapon {{ swapfile_file }}
when: created.changed
- name: SWAP | add swapfile to /etc/fstab
mount:
name: none
src: "{{ swapfile_file }}"
fstype: swap
opts: sw
passno: '0'
dump: '0'
state: present
- name: SWAP | configure vm.swappiness
sysctl:
name: vm.swappiness
value: "{{ swapfile_swappiness }}"
reload: true
state: present
when: swapfile_swappiness is defined