1
0
mirror of https://github.com/oVirt/ovirt-ansible-shutdown-env.git synced 2026-02-05 09:46:04 +01:00

Merge pull request #17 from tiraboschi/lint

Make ansible-lint and yamllint happy
This commit is contained in:
Simone Tiraboschi
2019-01-17 13:11:19 +01:00
committed by GitHub

View File

@@ -36,31 +36,48 @@
auth: "{{ ovirt_auth }}"
all_content: true
- set_fact:
- name: Set a variable
set_fact:
startup: false
- set_fact:
- name: Set a variable
set_fact:
startup: true
tags: [ 'never', 'startup' ]
tags: ['never', 'startup']
- set_fact:
he_hosts: "{{ ovirt_host | selectattr('hosted_engine', 'defined') | selectattr('hosted_engine.configured') | list }}"
- name: Define a query for HE hosts
set_fact:
he_hosts: >-
{{ ovirt_host | selectattr('hosted_engine', 'defined') | selectattr('hosted_engine.configured') | list }}
- set_fact:
non_he_hosts: "{{ ovirt_host | difference(he_hosts) }}"
- name: Define a query for non HE hosts
set_fact:
non_he_hosts: >-
{{ ovirt_host | difference(he_hosts) }}
- set_fact:
non_he_hosts_ipmi: "{{ non_he_hosts | selectattr('power_management', 'defined') | selectattr('power_management.enabled') | list }}"
- name: Define a query for non HE hosts with power management
set_fact:
non_he_hosts_ipmi: >-
{{ non_he_hosts | selectattr('power_management', 'defined') |
selectattr('power_management.enabled') | list }}
- set_fact:
- name: Define a query for non HE hosts without power management
set_fact:
non_he_hosts_noipmi: "{{ non_he_hosts | difference(non_he_hosts_ipmi) }}"
- set_fact:
hosts_ipmi: "{{ ovirt_host | selectattr('power_management', 'defined') | selectattr('power_management.enabled') | list }}"
- name: Define a query for hosts with power management
set_fact:
hosts_ipmi: >-
{{ ovirt_host | selectattr('power_management', 'defined') | selectattr('power_management.enabled') | list }}
- set_fact:
- name: Define commands
set_fact:
he_shutdown_cmd: >-
while hosted-engine --vm-status | grep "\"vm\": \"up\"" >/dev/null; do sleep 5; done; sanlock client shutdown -f 1; shutdown -h now
while hosted-engine --vm-status | grep "\"vm\": \"up\"" >/dev/null;
do sleep 5;
done;
sanlock client shutdown -f 1;
shutdown -h now
non_he_noipmi_shutdown_cmd: >-
while pgrep qemu-kvm >/dev/null; do sleep 5; done; shutdown -h now
gmaintenance_mode_cmd: >-
@@ -74,111 +91,126 @@
all_content: true
- block:
- name: Shutdown all VMs, except HostedEngine
ovirt_vm:
state: stopped
name: "{{ item.name }}"
auth: "{{ ovirt_auth }}"
wait: true
when: "item.origin != 'managed_hosted_engine'"
with_items:
- "{{ ovirt_vm }}"
ignore_errors: True
- name: Shutdown all VMs, except HostedEngine
ovirt_vm:
state: stopped
name: "{{ item.name }}"
auth: "{{ ovirt_auth }}"
wait: true
when: "item.origin != 'managed_hosted_engine'"
with_items:
- "{{ ovirt_vm }}"
ignore_errors: true
- name: Refresh VM list
ovirt_vm_facts:
auth: "{{ ovirt_auth }}"
all_content: true
- name: Refresh VM list
ovirt_vm_facts:
auth: "{{ ovirt_auth }}"
all_content: true
- name: Forcefully shutdown remaining VMs, except HostedEngine
ovirt_vm:
state: stopped
name: "{{ item.name }}"
auth: "{{ ovirt_auth }}"
wait: true
force: true
when: "item.origin != 'managed_hosted_engine' and item.status != 'down'"
with_items:
- "{{ ovirt_vm }}"
- name: Forcefully shutdown remaining VMs, except HostedEngine
ovirt_vm:
state: stopped
name: "{{ item.name }}"
auth: "{{ ovirt_auth }}"
wait: true
force: true
when: "item.origin != 'managed_hosted_engine' and item.status != 'down'"
with_items:
- "{{ ovirt_vm }}"
- name: Shutdown hosts, except HE ones, via IPMI (if configured)
ovirt_host:
state: stopped
name: "{{ item.name }}"
auth: "{{ ovirt_auth }}"
with_items:
- "{{ non_he_hosts_ipmi }}"
- name: Shutdown hosts, except HE ones, via IPMI (if configured)
ovirt_host:
state: stopped
name: "{{ item.name }}"
auth: "{{ ovirt_auth }}"
with_items:
- "{{ non_he_hosts_ipmi }}"
- name: Shutdown remaining non HE hosts
command: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /etc/pki/ovirt-engine/keys/engine_id_rsa -p {{item.ssh.port}} -t root@{{item.address}} '{{ non_he_noipmi_shutdown_cmd }}'
async: 1000
poll: 0
with_items:
- "{{ non_he_hosts_noipmi }}"
ignore_errors: True
- name: Shutdown remaining non HE hosts
command: >-
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-i /etc/pki/ovirt-engine/keys/engine_id_rsa
-p {{ item.ssh.port }}
-t root@{{ item.address }}
'{{ non_he_noipmi_shutdown_cmd }}'
async: 1000
poll: 0
with_items:
- "{{ non_he_hosts_noipmi }}"
ignore_errors: true
- name: Set global maintenance mode
command: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /etc/pki/ovirt-engine/keys/engine_id_rsa -p {{item.ssh.port}} -t root@{{item.address}} '{{ gmaintenance_mode_cmd }}'
with_items:
- "{{ he_hosts }}"
ignore_errors: True
register: globalmm
- name: Set global maintenance mode
command: >-
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-i /etc/pki/ovirt-engine/keys/engine_id_rsa
-p {{ item.ssh.port }} -t root@{{ item.address }}
'{{ gmaintenance_mode_cmd }}'
with_items:
- "{{ he_hosts }}"
ignore_errors: true
register: globalmm
- set_fact:
globalmm_set: "{{ globalmm.results | rejectattr('failed') | list | length }}"
when: globalmm is defined and globalmm.results is defined
- set_fact:
globalmm_set: "{{ globalmm.results | rejectattr('failed') | list | length }}"
when: globalmm is defined and globalmm.results is defined
- name: Enforce global maintenance mode
fail:
msg: >
Failed setting global maintenance mode.
when: he_hosts|length > 0 and globalmm_set|int == 0
- name: Enforce global maintenance mode
fail:
msg: >
Failed setting global maintenance mode.
when: he_hosts|length > 0 and globalmm_set|int == 0
- name: Warn about HE global maintenace mode
debug:
msg: >
HE global maintenance mode has been set; you have to exit it to get the engine VM started when needed
when: globalmm_set|int > 0
- name: Warn about HE global maintenace mode
debug:
msg: >
HE global maintenance mode has been set; you have to exit it to get the engine VM started when needed
when: globalmm_set|int > 0
- name: Shutdown of HE hosts
command: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /etc/pki/ovirt-engine/keys/engine_id_rsa -p {{item.ssh.port}} -t root@{{item.address}} '{{ he_shutdown_cmd }}'
async: 1000
poll: 0
with_items:
- "{{ he_hosts }}"
- name: Shutdown of HE hosts
command: >-
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-i /etc/pki/ovirt-engine/keys/engine_id_rsa -p {{ item.ssh.port }}
-t root@{{ item.address }} '{{ he_shutdown_cmd }}'
async: 1000
poll: 0
with_items:
- "{{ he_hosts }}"
- name: Shutdown engine host/VM
command: shutdown -h now
async: 1000
poll: 0
- name: Shutdown engine host/VM
command: shutdown -h now
async: 1000
poll: 0
when: not startup
- block:
- name: Power-on IPMI configured hosts
ovirt_host:
state: started
name: "{{ item.name }}"
auth: "{{ ovirt_auth }}"
with_items:
- "{{ hosts_ipmi }}"
- name: Power-on IPMI configured hosts
ovirt_host:
state: started
name: "{{ item.name }}"
auth: "{{ ovirt_auth }}"
with_items:
- "{{ hosts_ipmi }}"
- name: Unset global maintenance mode
command: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /etc/pki/ovirt-engine/keys/engine_id_rsa -p {{item.ssh.port}} -t root@{{item.address}} '{{ ugmaintenance_mode_cmd }}'
with_items:
- "{{ he_hosts }}"
ignore_errors: True
register: uglobalmm
- name: Unset global maintenance mode
command: >-
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-i /etc/pki/ovirt-engine/keys/engine_id_rsa -p {{ item.ssh.port }}
-t root@{{ item.address }} '{{ ugmaintenance_mode_cmd }}'
with_items:
- "{{ he_hosts }}"
ignore_errors: true
register: uglobalmm
- set_fact:
globalmm_set: "{{ uglobalmm.results | rejectattr('failed') | list | length }}"
when: uglobalmm is defined and uglobalmm.results is defined
- set_fact:
globalmm_set: "{{ uglobalmm.results | rejectattr('failed') | list | length }}"
when: uglobalmm is defined and uglobalmm.results is defined
- name: Enforce no global maintenance mode
fail:
msg: >
Failed unsetting global maintenance mode.
when: he_hosts|length > 0 and globalmm_set|int == 0
- name: Enforce no global maintenance mode
fail:
msg: >
Failed unsetting global maintenance mode.
when: he_hosts|length > 0 and globalmm_set|int == 0
when: startup
always: