ansible/playbooks/vhost_reboot.yml

76 lines
2 KiB
YAML

# requires --extra-vars="target=somevhost fqdn"
#General overview:
# talk to the vhost
# get back list of instances
# add each of their hostnames to an addhoc group
# halt each of them in a second play
# wait for them to die
# third play, reboot the vhost
# wait for vhost to come back
# TO BE DONE - should be fixable w/ansible 0.9
# wait for all of the instances to return(?)
# compare the first list to the second for state info
# how to do this:
# capture output of action: virt command=info before halting guests
# compare to same command after vhost comes back
# ansible 0.9 should allow us to preserve content of two registered variables
# across multiple plays
- name: find instances
hosts: $target
user: root
tasks:
- name: get list of guests
action: virt command=list_vms
register: vmlist
- name: add them to myvms_new group
local_action: add_host hostname=$item groupname=myvms_new
with_items: ${vmlist.list_vms}
- name: halt instances
hosts: myvms_new
user: root
serial: 1
tasks:
- name: tell nagios to shush
action: nagios action=downtime minutes=60 service=host host=$inventory_hostname
delegate_to: noc01.phx2.fedoraproject.org
ignore_errors: true
- name: halt the instances - to poweroff
action: command /sbin/halt -p
ignore_errors: true
# if one of them is down we don't care
- name: wait for them to die
local_action: wait_for port=22 delay=30 timeout=300 state=stopped host=${inventory_hostname}
- name: reboot vhost
hosts: $target
user: root
tasks:
- name: tell nagios to shush
action: nagios action=downtime minutes=60 service=host host=$inventory_hostname
delegate_to: noc01.phx2.fedoraproject.org
ignore_errors: true
- name: halt -r the $target
action: command /sbin/reboot
- name: wait for $target to come back - up to 6 minutes
local_action: wait_for host=$target port=22 delay=120 timeout=420
- name: look up vmlist
action: virt command=list_vms
register: newvmlist