Last active
July 6, 2020 02:17
-
-
Save waddles/bf8d88e611b8066036f40e5688ff6e76 to your computer and use it in GitHub Desktop.
Ansible play to expand disk and upgrade Ubuntu
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
- block: | |
- name: Upgrade OS to latest LTS release | |
shell: | | |
test $(lsb_release -si) = Ubuntu || exit 0 | |
parted /dev/sda unit s print | awk ' | |
/^Disk \// { | |
total = substr($3,0,length($3)-1) | |
} | |
$5 == "extended" { | |
xpnum = $1 | |
xsectors = substr($3,0,length($3)-1) | |
} | |
$5 == "logical" { | |
lpnum = $1 | |
lsectors = substr($3,0,length($3)-1) | |
} | |
END { | |
if (lsectors > 1 && lsectors < total - 1) { | |
printf "resizepart %s %ss\n", xpnum, total - 1 | |
printf "resizepart %s %ss\n", lpnum, total - 1 | |
} | |
}' | xargs parted --script /dev/sda | |
pvresize /dev/sda5 | |
lvresize /dev/ubuntu-vg/root -l '+100%FREE' | |
resize2fs /dev/ubuntu-vg/root | |
export DEBIAN_FRONTEND=noninteractive | |
apt-get update | |
apt-get upgrade -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --with-new-pkgs | |
apt-get autoremove -y | |
do-release-upgrade -f DistUpgradeViewNonInteractive | |
systemctl reboot | |
vars: | |
ansible_host: "{{ vm_ipaddress }}" | |
become: True | |
- name: Wait for reboot after OS upgrade | |
wait_for: | |
port: "{{ ansible_port | default('22') }}" | |
host: "{{ vm_ipaddress }}" | |
connection: local | |
become: no | |
when: | |
- nutanix.created is defined and nutanix.created | |
- "'linux' in group_names" | |
- not ansible_check_mode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This play gets run straight after provisioning a VM in Nutanix*. Typically I would run the full Ansible playbook then go back to upgrade the OS interactively but this play does the upgrade for me automatically.
Nutanix provisions a VM from a disk image clone of a minimal Ubuntu installation but with an expanded size.
This play
all before knowing anything about the VM except it's IP address.
Pros
Cons
* (actually there is a step in between to set the
vm_ipaddress
fact)