-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7420ddd
commit 8d7431d
Showing
4 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
# roles/swapsetup/defaults/main.yml | ||
|
||
swapsizegb: 4 | ||
swappath: /swapfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
# roles/swapsetup/tasks/main.yml | ||
|
||
- name: Ensure parameters | ||
assert: | ||
that: | ||
- ansible_distribution == 'Archlinux' | ||
|
||
- name: Check if swapfile exists | ||
shell: | ||
executable: /usr/bin/bash | ||
cmd: | | ||
if ( swapon --noheadings --show=NAME,TYPE,SIZE,USED --bytes | grep -P "^/swapfile\s+" ) | ||
then | ||
exit 98 | ||
fi | ||
exit 99 | ||
changed_when: False | ||
failed_when: swapfilestatus.rc not in [ 98, 99 ] | ||
register: swapfilestatus | ||
|
||
- name: Create swapfile | ||
filesize: | ||
path: "{{swappath}}" | ||
size: "{{swapsizegb}}G" | ||
owner: root | ||
group: root | ||
mode: u=rw,go=- | ||
when: swapfilestatus.rc == 99 | ||
register: mkswapfile | ||
|
||
- name: Format swapfile | ||
filesystem: | ||
dev: "{{swappath}}" | ||
fstype: swap | ||
when: mkswapfile.changed | ||
|
||
- name: Ensure swapfile in fstab | ||
lineinfile: | ||
path: /etc/fstab | ||
state: present | ||
regexp: '^{{swappath}}\s+' | ||
line: '{{swapfile}} none swap defaults 0 0' | ||
|
||
- name: Mount swapfile | ||
shell: | ||
executable: /usr/bin/bash | ||
cmd: | | ||
swapon "{{swappath}}" | ||
when: swapfilestatus.rc == 99 and mkswapfile.changed |