33d22c552e
When starting an imaged environment, the SSH keys on the host do not match the SSH keys in the containers. In this patch we ensure that if the 'all_containers' group is present, then the deploy-vms playbook will wait for them to come up and copy the new keys into them. It also adds the new public key into the authorized_keys. This ensures that the whole environment is ready to be used just as it was before imaging. We also remove the 'port' argument given to the wait_for_connection module because the argument is invalid. Change-Id: Iff0a3327c2031e0dd977e8e403b417e495fee14f
109 lines
3.0 KiB
YAML
109 lines
3.0 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
|
|
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)
|
|
virt:
|
|
command: status
|
|
name: "{{ inventory_hostname }}"
|
|
connection: local
|
|
register: vm_info
|
|
|
|
- name: Stop VM (rescue)
|
|
virt:
|
|
command: destroy
|
|
name: "{{ inventory_hostname }}"
|
|
connection: local
|
|
when: vm_info.status == 'running'
|
|
|
|
- name: Start VM (rescue)
|
|
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)
|
|
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
|
|
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 }}"
|