ff7cbf5548
This patch updates various playbooks within the MNAIO to use ansible collections, which is required for the latest Ansible versions. Change-Id: Ia7694e6b182dc8898b56730537cc99759a722b20
109 lines
3.1 KiB
YAML
109 lines
3.1 KiB
YAML
---
|
|
# Copyright 2018, Rackspace US, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in witing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
- name: Create vm_servers group
|
|
hosts: localhost
|
|
connection: local
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Create vm_servers group
|
|
ansible.builtin.add_host:
|
|
name: "{{ item }}"
|
|
groups: vm_servers
|
|
when:
|
|
- (hostvars[item]['server_vm'] | default(false)) | bool
|
|
with_items: "{{ groups['pxe_servers'] }}"
|
|
|
|
- name: VM Status
|
|
hosts: vm_servers
|
|
gather_facts: false
|
|
tasks:
|
|
- name: VM Connectivity Check
|
|
block:
|
|
- name: Wait for VM
|
|
wait_for_connection:
|
|
connect_timeout: 10
|
|
sleep: 20
|
|
timeout: "{{ vm_ssh_timeout }}"
|
|
rescue:
|
|
- name: Gather VM info (rescue)
|
|
community.libvirt.virt:
|
|
command: status
|
|
name: "{{ inventory_hostname }}"
|
|
connection: local
|
|
register: vm_info
|
|
|
|
- name: Stop VM (rescue)
|
|
community.libvirt.virt:
|
|
command: destroy
|
|
name: "{{ inventory_hostname }}"
|
|
connection: local
|
|
when: vm_info.status == 'running'
|
|
|
|
- name: Start VM (rescue)
|
|
community.libvirt.virt:
|
|
command: start
|
|
name: "{{ inventory_hostname }}"
|
|
connection: local
|
|
|
|
- name: Wait for VM (rescue)
|
|
wait_for_connection:
|
|
connect_timeout: 10
|
|
sleep: 20
|
|
timeout: "{{ vm_ssh_timeout }}"
|
|
register: vm_rescue
|
|
ignore_errors: true
|
|
|
|
- name: Gather VM info 2nd pass (rescue)
|
|
community.libvirt.virt:
|
|
command: status
|
|
name: "{{ inventory_hostname }}"
|
|
connection: local
|
|
register: vm_info_2
|
|
|
|
- name: Fail if VM still offline (rescue)
|
|
fail:
|
|
msg: "{{ inventory_hostname }} is not responding and cannot be rescued"
|
|
when:
|
|
- vm_info_2.status != 'running'
|
|
- vm_rescue.failed == 'true'
|
|
|
|
- name: Refresh the inventory
|
|
hosts: localhost
|
|
connection: local
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Refresh the inventory
|
|
meta: refresh_inventory
|
|
|
|
- name: Create vm_servers group
|
|
ansible.builtin.add_host:
|
|
name: "{{ item }}"
|
|
groups: vm_servers
|
|
when:
|
|
- (hostvars[item]['server_vm'] | default(false)) | bool
|
|
with_items: "{{ groups['pxe_servers'] }}"
|
|
|
|
- name: Container Status
|
|
hosts: all_containers
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Wait for container connectivity
|
|
wait_for_connection:
|
|
connect_timeout: 10
|
|
delay: 3
|
|
sleep: 20
|
|
timeout: "{{ vm_ssh_timeout }}"
|