ansible/playbooks/vhost_halt_guests.yml
Ryan Lerch 462176464b ansiblelint fixes-- fqcn[action-core] - command to ansible.builtin.command
Replaces many references to  command: with ansible.builtin.command

Signed-off-by: Ryan Lerch <rlerch@redhat.com>
2025-01-15 11:26:47 +10:00

53 lines
1.4 KiB
YAML

# requires --extra-vars="vhost=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: "{{ vhost }}"
user: root
tasks:
- name: Get list of guests
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
nagios: action=silence host={{ inventory_hostname_short }}
delegate_to: noc01.iad2.fedoraproject.org
- name: Echo-y
ansible.builtin.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 }}