openstack-ansible-nspawn_co.../tests/test-nspawn-containers-crea...

88 lines
2.5 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 writing, 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: Gather host facts
hosts: localhost
connection: local
- name: Create container(s)
hosts: all_containers
gather_facts: false
become: true
pre_tasks:
- name: Get container status
command: machinectl status "{{ inventory_hostname }}"
register: machinectl_container_status
failed_when: false
changed_when: false
delegate_to: "{{ physical_host }}"
- name: Get container image status
command: machinectl image-status "{{ inventory_hostname }}"
register: machinectl_container_image_status
failed_when: false
changed_when: false
delegate_to: "{{ physical_host }}"
- name: Poweroff container
command: "machinectl poweroff {{ inventory_hostname }}"
register: machinectl_poweroff
retries: 3
delay: 2
until: machinectl_poweroff is success
delegate_to: "{{ physical_host }}"
failed_when: false
when:
- machinectl_container_status.rc == 0
tags:
- skip_ansible_lint
- name: Remove container
command: "machinectl remove {{ inventory_hostname }}"
register: machinectl_remove
retries: 3
delay: 2
until: machinectl_remove is success
delegate_to: "{{ physical_host }}"
failed_when: false
when:
- machinectl_container_image_status.rc == 0
tags:
- skip_ansible_lint
- name: Container cleanup
file:
path: "{{ item }}"
state: "absent"
with_items:
- "/openstack/log/{{ inventory_hostname }}"
- "/openstack/{{ inventory_hostname }}"
delegate_to: "{{ physical_host }}"
roles:
- role: "nspawn_container_create"
post_tasks:
- name: Create detail gathering script
template:
src: "dump-container-details.sh.j2"
dest: "/opt/dump-{{ inventory_hostname }}-details.sh"
mode: "0755"
- name: Collect details
command: "/opt/dump-{{ inventory_hostname }}-details.sh"
tags:
- skip_ansible_lint