Replaces many references to command: with ansible.builtin.command Signed-off-by: Ryan Lerch <rlerch@redhat.com>
64 lines
1.5 KiB
YAML
64 lines
1.5 KiB
YAML
#
|
|
# 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
|
|
ansible.builtin.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
|
|
ansible.builtin.command: /sbin/shutdown -h 1
|