tripleo-ansible/tripleo_ansible/roles/tripleo-container-manage/tasks/main.yml

77 lines
2.9 KiB
YAML

---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# 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.
# "tripleo-container-manage" will search for and load any operating system variable file
# found within the "vars/" path. If no OS files are found the task will skip.
- name: Gather variables for each operating system
include_vars: "{{ item }}"
with_first_found:
- skip: true
files:
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
- "{{ ansible_os_family | lower }}.yml"
tags:
- always
- name: Create container logs path
file:
path: "{{ tripleo_container_manage_log_path }}"
state: directory
owner: root
group: root
become: true
when:
- tripleo_container_manage_log_path is defined
- name: Generate containers configs data
no_log: true
block:
- name: "Find all hashed configs configs for step {{ step }}"
find:
paths: "/var/lib/tripleo-config/container-startup-config/step_{{ step }}"
patterns: 'hashed-*.json'
register: hashed_files
- name: "Read config for each container at step {{ step }}"
slurp:
src: "{{ item.path }}"
register: containers_data
loop: "{{ hashed_files.files }}"
- set_fact:
container_hash: "{'{{ item.source|basename|regex_replace('^hashed-','')|regex_replace('.json$','')}}': {{item.content|b64decode|from_json}} }"
register: container_hashes
loop: "{{ containers_data['results'] }}"
- set_fact:
container_hash: "{{ item.ansible_facts.container_hash | combine(item.ansible_facts.container_hash) }}"
register: container_hashes
loop: "{{ container_hashes.results }}"
- set_fact:
all_containers_hash: "{{ container_hashes.results | map(attribute='ansible_facts.container_hash') | list | singledict() }}"
- name: Manage containers with Podman
when:
- tripleo_container_cli == 'podman'
become: true
block:
- name: "Manage Podman containers at step {{ step }}"
include_tasks: podman.yaml
loop: "{{ all_containers_hash | subsort(attribute='start_order', null_value=0) }}"