mirror of
https://github.com/kneutron/ansitest.git
synced 2025-02-06 05:08:25 +08:00
Update increase-swap-partition.yml
got it working in test env, had to indent evy
This commit is contained in:
parent
d935266d42
commit
3a5e225ed4
@ -3,67 +3,110 @@
|
|||||||
# reboot to get new disk size
|
# reboot to get new disk size
|
||||||
# get info on existing swap: swapon -s
|
# get info on existing swap: swapon -s
|
||||||
# TURN OFF swap: swapoff -a
|
# TURN OFF swap: swapoff -a
|
||||||
# blkid|grep swap && reuse UUID so no modify fstab
|
# fstab grep swap && reuse UUID so no modify fstab
|
||||||
|
|
||||||
# NOTE this script relies on swap being on sdb1, and only 1 swap partition
|
# NOTE this script relies on swap being on sdb1, and only 1 swap partition
|
||||||
|
|
||||||
- name: install parted pkg if missing
|
- hosts: testvms
|
||||||
|
tasks:
|
||||||
|
|
||||||
|
- name: install parted pkg if missing
|
||||||
package:
|
package:
|
||||||
name: parted
|
name: parted
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: get swapinfo - partition size b4
|
- name: get swapinfo - partition size b4
|
||||||
shell: "swapon -s > /tmp/swapinfo.txt"
|
shell: "swapon -s > /root/swapinfo.txt"
|
||||||
args:
|
|
||||||
creates: /tmp/swapinfo.txt
|
|
||||||
|
|
||||||
# straight up copied from patch
|
# straight up copied from patch
|
||||||
- name: reboot server to get latest disk size
|
- name: reboot server to get latest disk size
|
||||||
reboot:
|
reboot:
|
||||||
reboot_timeout: 600
|
reboot_timeout: 600
|
||||||
test_command: uptime
|
test_command: uptime
|
||||||
post_reboot_delay: 45
|
post_reboot_delay: 45
|
||||||
|
|
||||||
- name: turn swap off
|
- name: turn swap off
|
||||||
shell: "swapoff -a; free"
|
shell: swapoff -a
|
||||||
|
|
||||||
- name: reuse existing swap uuid
|
- name: VERIFY swap off
|
||||||
shell: "blkid |grep swap |head -n 1 |awk '{print $2}' > /tmp/blkidswapinfo.txt"
|
shell: "free |awk '{print $2}' > /root/swapalloc.txt"
|
||||||
args:
|
args:
|
||||||
creates: /tmp/blkidswapinfo.txt
|
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:
|
# expected result:
|
||||||
# UUID="BLAH"
|
# UUID=BLAH
|
||||||
|
|
||||||
# TODO Fail if swap not on sdb
|
# TODO Fail if swap not on sdb
|
||||||
|
|
||||||
- name: delete existing swap on sdb
|
- name: delete existing swap on sdb
|
||||||
parted:
|
parted:
|
||||||
device: /dev/sdb
|
device: /dev/sdb
|
||||||
number: 1
|
number: 1
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: create new partition with existing blkid
|
# have to shell this because parted module not support swap
|
||||||
parted:
|
- name: create new swap partition using all space on sdb
|
||||||
device: /dev/sdb
|
shell: "parted -s /dev/sdb mkpart primary linux-swap 1MiB 100%"
|
||||||
number: 1
|
|
||||||
part_type: primary
|
|
||||||
part_start: 0%
|
|
||||||
part_end: 100%
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: change partid to 82/swap
|
- name: verify new partition
|
||||||
shell: |
|
shell: "parted -s /dev/sdb1 print"
|
||||||
"parted -s /dev/sdb1 print"
|
|
||||||
"parted -s /dev/sdb1 set swap on"
|
|
||||||
"parted -s /dev/sdb1 print"
|
|
||||||
|
|
||||||
- name: remake swap partition with old UUID / no fstab changes
|
# - name: create new partition with existing blkid
|
||||||
shell: |
|
# parted:
|
||||||
mkswap -U $(awk -F\" '{print $2}' /tmp/blkidswapinfo.txt)
|
# device: /dev/sdb
|
||||||
"blkid |grep swap"
|
# number: 1
|
||||||
|
# part_type: primary
|
||||||
|
# part_start: 0%
|
||||||
|
# part_end: 100%
|
||||||
|
# state: present
|
||||||
|
|
||||||
- name: turn swap back on
|
# - name: change partid to 82/swap
|
||||||
shell: "swapon -a; swapon -s; free"
|
# 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"
|
||||||
|
|
||||||
|
- 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
|
# - name: cleanup
|
||||||
|
|
||||||
@ -71,3 +114,5 @@
|
|||||||
# Author: dave.bechtel@asmr
|
# Author: dave.bechtel@asmr
|
||||||
# script to delete and expand existing swap partition on sdb1
|
# script to delete and expand existing swap partition on sdb1
|
||||||
# 2020.0820 alpha ver
|
# 2020.0820 alpha ver
|
||||||
|
# 2020.0821 got it working in test env
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user