Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically setup swap partition, now with disk size detection #125

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions playbooks/tasks/cloudhost.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
- include: swap.yaml
when: mode == "pre"

- name: Ensure base packages are up to date
yum:
name: '*'
Expand Down
34 changes: 34 additions & 0 deletions playbooks/tasks/swap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---

# try to find swap disk -- skip if it is already partitioned or not found
- name: "Find swap disk"
set_fact:
swap_disk: "/dev/{{ item.key }}"
with_dict: "{{ ansible_devices }}"
when: "item.value.partitions|length == 0 and (item.value.size == '12.00 GB' or item.value.size == '6.00 GB')"

# parted module doesn't support swap fs type, must use shell
- name: "Partition swap disk"
shell: 'parted {{ swap_disk }} -s -- mklabel gpt mkpart "swap" linux-swap 1 -1'
when: swap_disk is defined
register: swappart

- name: "Format swap partition"
shell: "mkswap {{ swap_disk }}1"
when: swap_disk is defined and swappart.rc == 0
register: swapFS

- name: "Activate swap partition"
shell: "swapon {{ swap_disk }}1"
when: swap_disk is defined and swapFS.rc == 0

- name: "Write swap entry to fstab"
mount:
name: none
src: "{{ swap_disk }}1"
fstype: swap
opts: defaults
passno: '0'
dump: '0'
state: present
when: swap_disk is defined and swapFS.rc == 0