ansible/playbooks/vhost_reboot.yml

91 lines
2.4 KiB
YAML
Raw Normal View History

# requires --extra-vars="target=somevhost fqdn"
#General overview:
2012-11-21 17:56:10 +00:00
# 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
2012-11-21 17:56:10 +00:00
# third play, reboot the vhost
# wait for vhost to come back
# TO BE DONE - should be fixable w/ansible 0.9
2012-11-21 17:56:10 +00:00
# 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
2012-11-21 17:56:10 +00:00
- name: find instances
hosts: $target
2012-11-21 17:56:10 +00:00
user: root
tasks:
- name: get list of guests
action: virt command=list_vms
register: vmlist
2012-11-21 17:59:07 +00:00
- name: add them to myvms_new group
2012-11-21 17:56:10 +00:00
local_action: add_host hostname=$item groupname=myvms_new
with_items: ${vmlist.list_vms}
2012-11-21 17:56:10 +00:00
- name: halt instances
hosts: myvms_new
user: root
serial: 1
2012-11-21 17:56:10 +00:00
tasks:
2013-10-02 19:40:24 +00:00
- name: schedule host downtime
2013-11-19 19:53:27 +00:00
action: nagios action=downtime minutes=30 service=host host={{ inventory_hostname_short }}
delegate_to: noc01.phx2.fedoraproject.org
ignore_errors: true
2013-11-21 20:19:48 +00:00
when: not ansible_domain.startswith('stg')
- name: schedule host downtime
action: nagios action=downtime minutes=30 service=host host={{ inventory_hostname_short }}.stg
delegate_to: noc01.phx2.fedoraproject.org
ignore_errors: true
when: ansible_domain.startswith('stg')
2013-05-07 21:56:58 +00:00
- name: halt the instances - to poweroff
action: command /sbin/halt -p
2012-11-21 18:45:20 +00:00
ignore_errors: true
# if one of them is down we don't care
- name: wait for the whole set to die.
hosts: myvms_new
user: root
tasks:
2012-11-21 18:45:20 +00:00
- name: wait for them to die
local_action: wait_for port=22 delay=30 timeout=300 state=stopped host=${inventory_hostname}
2012-11-21 17:56:10 +00:00
2012-11-21 18:22:03 +00:00
- name: reboot vhost
hosts: $target
2012-11-21 18:22:03 +00:00
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
2012-11-21 18:45:20 +00:00
- name: wait for $target to come back - up to 6 minutes
local_action: wait_for host=$target port=22 delay=120 timeout=420
2012-11-21 18:45:20 +00:00
- name: look up vmlist
2012-11-21 18:45:20 +00:00
action: virt command=list_vms
register: newvmlist
- name: sync time
command: ntpdate -u 66.187.233.4