2013-11-21 21:52:05 +00:00
|
|
|
#
|
|
|
|
# This playbook lets you safely reboot a virthost and all it's guests.
|
|
|
|
#
|
2013-03-04 22:37:13 +00:00
|
|
|
# requires --extra-vars="target=somevhost fqdn"
|
2012-11-21 21:09:19 +00:00
|
|
|
|
|
|
|
#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
|
2012-11-21 21:09:19 +00:00
|
|
|
# wait for them to die
|
2012-11-21 17:56:10 +00:00
|
|
|
# third play, reboot the vhost
|
|
|
|
# wait for vhost to come back
|
2012-11-21 21:09:19 +00:00
|
|
|
|
2013-11-21 21:52:05 +00:00
|
|
|
# TODO: Figure out how to compare virt info pre and post boot.
|
2012-11-21 17:56:10 +00:00
|
|
|
|
|
|
|
- name: find instances
|
2013-11-21 21:52:05 +00:00
|
|
|
hosts: "{{ target }}"
|
|
|
|
gather_facts: False
|
2012-11-21 17:56:10 +00:00
|
|
|
user: root
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: get list of guests
|
2013-11-21 21:52:05 +00:00
|
|
|
virt: command=list_vms
|
2012-11-21 17:56:10 +00:00
|
|
|
register: vmlist
|
2012-11-21 17:59:07 +00:00
|
|
|
|
2013-11-21 21:52:05 +00:00
|
|
|
# - name: get info on guests (prereboot)
|
|
|
|
# virt: command=info
|
|
|
|
# register: vminfo_pre
|
|
|
|
|
2012-11-21 21:09:19 +00:00
|
|
|
- name: add them to myvms_new group
|
2013-11-21 22:07:02 +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
|
2013-11-21 21:52:05 +00:00
|
|
|
gather_facts: False
|
2013-01-28 21:27:18 +00:00
|
|
|
serial: 1
|
2012-11-21 17:56:10 +00:00
|
|
|
|
|
|
|
tasks:
|
2013-11-21 21:52:05 +00:00
|
|
|
- name: schedule regular host downtime
|
|
|
|
nagios: action=downtime minutes=30 service=host host={{ inventory_hostname_short }}
|
2013-03-01 16:24:16 +00:00
|
|
|
delegate_to: noc01.phx2.fedoraproject.org
|
2013-05-07 21:50:45 +00:00
|
|
|
ignore_errors: true
|
2013-11-21 22:41:51 +00:00
|
|
|
when: not inventory_hostname.startswith('stg')
|
2013-11-21 20:19:48 +00:00
|
|
|
|
2013-11-21 21:52:05 +00:00
|
|
|
- name: schedule stg host downtime
|
|
|
|
nagios: action=downtime minutes=30 service=host host={{ inventory_hostname_short }}.stg
|
2013-11-21 20:19:48 +00:00
|
|
|
delegate_to: noc01.phx2.fedoraproject.org
|
|
|
|
ignore_errors: true
|
2013-11-21 22:07:02 +00:00
|
|
|
when: inventory_hostname.startswith('stg')
|
2013-01-28 21:27:18 +00:00
|
|
|
|
2013-11-21 21:52:05 +00:00
|
|
|
- name: halt the vm instances - to poweroff
|
|
|
|
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
|
|
|
|
|
2013-11-21 10:24:17 +00:00
|
|
|
- name: wait for the whole set to die.
|
|
|
|
hosts: myvms_new
|
2013-11-21 21:52:05 +00:00
|
|
|
gather_facts: False
|
2013-11-21 10:24:17 +00:00
|
|
|
user: root
|
|
|
|
|
|
|
|
tasks:
|
2012-11-21 18:45:20 +00:00
|
|
|
- name: wait for them to die
|
2013-11-21 21:52:05 +00:00
|
|
|
local_action: wait_for port=22 delay=30 timeout=300 state=stopped host={{ inventory_hostname }}
|
2013-11-21 10:24:17 +00:00
|
|
|
|
2012-11-21 18:22:03 +00:00
|
|
|
- name: reboot vhost
|
2013-11-21 21:52:05 +00:00
|
|
|
hosts: "{{ target }}"
|
|
|
|
gather_facts: False
|
2012-11-21 18:22:03 +00:00
|
|
|
user: root
|
|
|
|
|
|
|
|
tasks:
|
2013-03-01 16:24:16 +00:00
|
|
|
- name: tell nagios to shush
|
2013-11-21 21:52:05 +00:00
|
|
|
nagios: action=downtime minutes=60 service=host host={{ inventory_hostname }}
|
2013-03-01 16:24:16 +00:00
|
|
|
delegate_to: noc01.phx2.fedoraproject.org
|
2013-05-07 21:50:45 +00:00
|
|
|
ignore_errors: true
|
2013-01-28 21:27:18 +00:00
|
|
|
|
2013-11-21 21:52:05 +00:00
|
|
|
- name: reboot the virthost
|
|
|
|
command: /sbin/reboot
|
2012-11-21 18:45:20 +00:00
|
|
|
|
2013-11-21 21:52:05 +00:00
|
|
|
- name: wait for virthost 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
|
|
|
|
2013-12-19 20:25:13 +00:00
|
|
|
- name: wait for libvirtd to come back on the virthost
|
2013-12-19 21:07:50 +00:00
|
|
|
wait_for: path=/var/run/libvirtd.pid state=present
|
2013-12-19 20:25:13 +00:00
|
|
|
|
2012-11-21 18:58:50 +00:00
|
|
|
- name: look up vmlist
|
2013-11-21 21:52:05 +00:00
|
|
|
virt: command=list_vms
|
2012-11-21 18:45:20 +00:00
|
|
|
register: newvmlist
|
2012-11-21 21:09:19 +00:00
|
|
|
|
2013-11-21 20:36:36 +00:00
|
|
|
- name: sync time
|
|
|
|
command: ntpdate -u 66.187.233.4
|
2013-11-21 21:52:05 +00:00
|
|
|
|
|
|
|
- name: serverbeach hosts need a special iptables config
|
|
|
|
command: /root/fix-iptables.sh
|
|
|
|
when: inventory_hostname_short.startswith('serverbeach')
|
|
|
|
|
|
|
|
# - name: get info on guests (postreboot)
|
|
|
|
# virt: command=info
|
|
|
|
# register: vminfo_post
|
|
|
|
|