107 lines
5.5 KiB
YAML
107 lines
5.5 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.
|
|
|
|
- name: "Async container create/run"
|
|
async: "{{ (not ansible_check_mode | bool) | ternary('300', omit) }}"
|
|
poll: "{{ (not ansible_check_mode | bool) | ternary('0', omit) }}"
|
|
register: create_async_results
|
|
loop: "{{ batched_container_data | haskey(attribute='action', reverse=True) }}"
|
|
loop_control:
|
|
loop_var: container_data
|
|
podman_container:
|
|
cap_add: "{{ lookup('dict', container_data).value.cap_add | default(omit) }}"
|
|
cap_drop: "{{ lookup('dict', container_data).value.cap_drop | default(omit) }}"
|
|
command: "{{ lookup('dict', container_data).value.command | default(omit) }}"
|
|
conmon_pidfile: "/var/run/{{ lookup('dict', container_data).key }}.pid"
|
|
cpu_shares: "{{ lookup('dict', container_data).value.cpu_shares | default(omit) | int }}"
|
|
# cpuset_cpus: "{{ lookup('dict', container_data).value.cpuset_cpus | default(omit) }}"
|
|
debug: true
|
|
detach: "{{ lookup('dict', container_data).value.detach | default(true) }}"
|
|
entrypoint: "{{ lookup('dict', container_data).value.entrypoint | default(omit) }}"
|
|
env: "{{ lookup('dict', container_data).value.environment | default(omit) }}"
|
|
env_file: "{{ lookup('dict', container_data).value.env_file | default(omit) }}"
|
|
etc_hosts: "{{ lookup('dict', container_data).value.extra_hosts | default({}) }}"
|
|
group_add: "{{ lookup('dict', container_data).value.group_add | default(omit) }}"
|
|
hostname: "{{ lookup('dict', container_data).value.hostname | default(omit) }}"
|
|
image: "{{ lookup('dict', container_data).value.image }}"
|
|
interactive: "{{ lookup('dict', container_data).value.interactive | default(false) }}"
|
|
ipc: "{{ lookup('dict', container_data).value.ipc | default(omit) }}"
|
|
label:
|
|
config_id: "{{ tripleo_container_manage_config_id }}"
|
|
container_name: "{{ lookup('dict', container_data).key }}"
|
|
managed_by: tripleo_ansible
|
|
config_data: "{{ lookup('dict', container_data).value }}"
|
|
log_driver: 'k8s-file'
|
|
log_opt: "path={{ tripleo_container_manage_log_path }}/{{ lookup('dict', container_data).key }}.log"
|
|
memory: "{{ lookup('dict', container_data).value.mem_limit | default(omit) }}"
|
|
memory_swap: "{{ lookup('dict', container_data).value.mem_swappiness | default(omit) }}"
|
|
name: "{{ lookup('dict', container_data).key }}"
|
|
net: "{{ lookup('dict', container_data).value.net | default('none') }}"
|
|
pid: "{{ lookup('dict', container_data).value.pid | default(omit) }}"
|
|
privileged: "{{ lookup('dict', container_data).value.privileged | default(false) }}"
|
|
rm: "{{ lookup('dict', container_data).value.remove | default(false) }}"
|
|
security_opt: "{{ lookup('dict', container_data).value.security_opt | default(omit) }}"
|
|
state: present
|
|
stop_signal: "{{ lookup('dict', container_data).value.stop_signal | default(omit) }}"
|
|
stop_timeout: "{{ lookup('dict', container_data).value.stop_grace_period | default(omit) | int }}"
|
|
tty: "{{ lookup('dict', container_data).value.tty | default(false) }}"
|
|
ulimit: "{{ lookup('dict', container_data).value.ulimit | default(omit) }}"
|
|
user: "{{ lookup('dict', container_data).value.user | default(omit) }}"
|
|
uts: "{{ lookup('dict', container_data).value.uts | default(omit) }}"
|
|
volume: "{{ lookup('dict', container_data).value.volumes | default(omit) }}"
|
|
volumes_from: "{{ lookup('dict', container_data).value.volumes_from | default([]) }}"
|
|
|
|
- name: "Check podman create status"
|
|
async_status:
|
|
jid: "{{ create_async_result_item.ansible_job_id }}"
|
|
loop: "{{ create_async_results.results }}"
|
|
loop_control:
|
|
loop_var: "create_async_result_item"
|
|
register: create_async_poll_results
|
|
until: create_async_poll_results.finished
|
|
retries: 30
|
|
when:
|
|
- not ansible_check_mode|bool
|
|
|
|
# This fact will be used in systemd playbook to figure out if whether or not
|
|
# a container managed by systemd needs to be restarted
|
|
- name: "Create a list of containers which changed"
|
|
set_fact:
|
|
containers_changed: >-
|
|
{{ create_async_results.results | selectattr('changed', 'equalto', true) |
|
|
map(attribute='container_data') | list | list_of_keys }}
|
|
|
|
- name: Block for container commands
|
|
when:
|
|
- ansible_check_mode|bool
|
|
block:
|
|
- name: "Create a list of podman commands that are run for containers with changes"
|
|
set_fact:
|
|
containers_commands: >-
|
|
{{ create_async_results.results | selectattr('changed', 'equalto', true) |
|
|
map(attribute='podman_actions') | default([]) | list }}
|
|
- name: "Print the list of commands that are run for containers with changes"
|
|
debug:
|
|
var: containers_commands
|
|
- name: "Append the list of all podman commands that are run for containers with changes"
|
|
set_fact:
|
|
all_containers_commands: "{{ containers_commands|default([], true) + (all_containers_commands | default([]) | list) }}"
|
|
|
|
- name: "Print the list of containers which changed"
|
|
debug:
|
|
var: containers_changed
|
|
when: tripleo_container_manage_debug | bool
|