-
Notifications
You must be signed in to change notification settings - Fork 14
/
increase-swap-partition.yml
121 lines (94 loc) · 3 KB
/
increase-swap-partition.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---
# pseudocode:
# reboot to get new disk size
# get info on existing swap: swapon -s
# TURN OFF swap: swapoff -a
# fstab grep swap && reuse UUID so no modify fstab
# NOTE this script relies on swap being on sdb1, and only 1 swap partition
- hosts: testvms
tasks:
- name: install parted pkg if missing
package:
name: parted
state: present
- name: get swapinfo - partition size b4
shell: "swapon -s > /root/swapinfo.txt"
# straight up copied from patch
- name: reboot server to get latest disk size
reboot:
reboot_timeout: 600
test_command: uptime
post_reboot_delay: 45
- name: turn swap off
shell: swapoff -a
- name: VERIFY swap off
shell: "free |awk '{print $2}' > /root/swapalloc.txt"
args:
creates: /root/swapalloc.txt
# TODO - print $2 and fail !=0
- name: reuse existing swap uuid - get UUID from fstab instead of blkid, less trouble
shell: "grep swap /etc/fstab |head -n 1 |awk '{print $1}' > /root/blkidswapinfo.txt"
# shell: "blkid |grep swap |head -n 1 |awk '{print $2}' > /root/blkidswapinfo.txt"
args:
creates: /root/blkidswapinfo.txt
# expected result:
# UUID=BLAH
# TODO Fail if swap not on sdb
- name: delete existing swap on sdb
parted:
device: /dev/sdb
number: 1
state: absent
# have to shell this because parted module not support swap
- name: create new swap partition using all space on sdb
shell: "parted -s /dev/sdb mkpart primary linux-swap 1MiB 100%"
- name: verify new partition
shell: parted -s /dev/sdb1 print
register: partedprintout
- debug: msg="DEBUG {{ partedprintout.stdout }}"
# - name: create new partition with existing blkid
# parted:
# device: /dev/sdb
# number: 1
# part_type: primary
# part_start: 0%
# part_end: 100%
# state: present
# - name: change partid to 82/swap
# shell: |
# "parted -s /dev/sdb1 print"
# "parted -s /dev/sdb1 set swap on"
# "parted -s /dev/sdb1 print"
- name: replace UUID=blah and get just blah
replace:
path: /root/blkidswapinfo.txt
regexp: "{{ item }}"
replace: ''
with_items:
- 'UUID='
# - '"'
- name: turn swap off AGAIN JIC, cuz WE WERE GETTING ERRORS THAT IT WAS STILL MOUNTED!!!
shell: swapoff -a
become: true
- name: remake swap partition with old UUID / no fstab changes
shell: mkswap -U $(awk '{print $1}' /root/blkidswapinfo.txt) /dev/sdb1
- name: verify swap from blkid
shell: "blkid |grep swap"
register: blkidoutput
- debug: msg="DEBUG {{ blkidoutput.stdout }}"
- name: turn swap back on
shell: swapon -a
- name: verify changes
shell: swapon -s
register: swaponS
- debug: msg="DEBUG {{ swaponS.stdout }}"
- name: verify changes2
shell: free
register: swaponS
- debug: msg="DEBUG {{ swaponS.stdout }}"
# - name: cleanup
##################
# Author: dave.bechtel@asmr
# script to delete and expand existing swap partition on sdb1
# 2020.0820 alpha ver
# 2020.0821 got it working in test env