From cf1d4d544b539196d61acb4a0d2e568f57672636 Mon Sep 17 00:00:00 2001 From: Patrick Uiterwijk Date: Fri, 15 Dec 2017 15:39:23 +0000 Subject: [PATCH] Add rudimentary vhost poweroff playbook Signed-off-by: Patrick Uiterwijk --- playbooks/vhost_poweroff.yml | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 playbooks/vhost_poweroff.yml diff --git a/playbooks/vhost_poweroff.yml b/playbooks/vhost_poweroff.yml new file mode 100644 index 0000000000..6c2e1712dd --- /dev/null +++ b/playbooks/vhost_poweroff.yml @@ -0,0 +1,63 @@ +# +# This playbook lets you safely reboot a virthost and all it's guests. +# +# 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 + +# TODO: Figure out how to compare virt info pre and post boot. + +- name: find instances + hosts: "{{ target }}" + gather_facts: False + user: root + + tasks: + - name: get list of guests + virt: command=list_vms + register: vmlist + +# - name: get info on guests (prereboot) +# virt: command=info +# register: vminfo_pre + + - 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 + gather_facts: False + serial: 1 + + tasks: + - name: halt the vm instances - to poweroff + command: /sbin/shutdown -h 1 + ignore_errors: true + # if one of them is down we don't care + +- name: wait for the whole set to die. + hosts: myvms_new + gather_facts: False + user: root + + tasks: + - 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 }}" + gather_facts: False + user: root + + tasks: + - name: halt the virthost + command: /sbin/shutdown -h 1