43 lines
2.4 KiB
YAML
Executable File
43 lines
2.4 KiB
YAML
Executable File
#!/usr/bin/env ansible-playbook --forks 50
|
|
---
|
|
# Reboot a series of compute nodes in a rolling fasion, verifying all VMs come back up on
|
|
# each node before going on to reboot the next group.
|
|
#
|
|
# Author: Kris Lindgren <klindgren@godaddy.com>
|
|
#
|
|
# This playbook requires the following variables:
|
|
# api_server - this is the server that runs the nova-api instance that we will use to get a list of the running vm's on compute nodes
|
|
# hosts - this is the host group to perform the rolling reboot on typically would be: *-compute
|
|
|
|
# This playbook also except the following *OPTIONAL* variables:
|
|
# reboot_parallelism (5) - How many hosts to reboot at once
|
|
# reboot_check_port - This is the port to check to see if the server has come back online (22)
|
|
# wait_delay - This is how long to wait between checks (120 seconds)
|
|
# wait_timeout - This is the maximum time to wait until we move on (1200 seconds)
|
|
# pause_for_host_boot - This is the time to wait for the host to fully restart (3 minutes)
|
|
|
|
# Example:
|
|
# ansible-playbook compute-rolling-reboot.yaml -k -K --extra-vars "api_server=api01 hosts=compute"
|
|
|
|
- hosts: '{{ hosts }}'
|
|
sudo: yes
|
|
serial: "{{ reboot_parallelism | default('5') }}"
|
|
tasks:
|
|
- name: Gather list of all running vm's on the host
|
|
shell: source /root/keystonerc_admin; nova list --all-tenants --status Active --host {{inventory_hostname}} --fields host,OS-EXT-SRV-ATTR:instance_name,status | grep ACTIVE | awk -F" | " '{if(a[$4]){a[$4]=a[$4]","$2"+"$6} else { a[$4]=$2"+"$6}} END {for (i in a) { print i":"a[i]} }'
|
|
register: running_vms
|
|
delegate_to: '{{ api_server }}'
|
|
|
|
- include: ../tasks/rolling-reboot.yaml
|
|
|
|
- name: ensure that nova-compute is started
|
|
service: name=openstack-nova-compute state=started
|
|
register: novacompute
|
|
|
|
- name: Verify running vm's are still running
|
|
shell: rc=$(echo "0"); vmlist=$( echo "{{running_vms.stdout }}" | grep {{inventory_hostname }} |cut -d":" -f2,2 |awk -F"," '{for (i=1; i<=NF; i++) print $i}'); virshlist=$( virsh list | grep running | awk '{print $2}'); for i in $vmlist; do vm=$( echo $i | cut -d"+" -f2,2 ); tmp=$( echo "$virshlist" | grep $vm); if [ $? -eq 1 ]; then uuid=$( echo "$i" | cut -d"+" -f1,1); echo "$uuid"; rc=$(echo "1"); fi; done; if [ "$rc" == "1" ]; then false; else true; fi
|
|
register: vms_not_running
|
|
when: novacompute.state == "started"
|
|
- debug: msg="{{vms_not_running}}"
|
|
when: vms_not_running.rc == 1
|