Merge "Expose tripleo_container_manage_clean_orphans var"
This commit is contained in:
commit
3c962d9cc9
@ -111,6 +111,8 @@ Roles variables
|
||||
| tripleo_container_manage_config_overrides | {} | Allows to override any |
|
||||
| | | container configuration |
|
||||
+------------------------------------------------+-----------------------------+----------------------------+
|
||||
| tripleo_container_manage_clean_orphans | true | Option to clean orphans |
|
||||
+------------------------------------------------+-----------------------------+----------------------------+
|
||||
| tripleo_container_manage_valid_exit_code | [] | Allow to check if a |
|
||||
| | | container returned the |
|
||||
| | | exit code in parameter. |
|
||||
@ -188,6 +190,7 @@ overrides the image setting in one-off.
|
||||
tripleo_container_manage_config_patterns: 'haproxy.json'
|
||||
tripleo_container_manage_config: "/var/lib/tripleo-config/container-startup-config/step_1"
|
||||
tripleo_container_manage_config_id: "tripleo_step1"
|
||||
tripleo_container_manage_clean_orphans: false
|
||||
tripleo_container_manage_config_overrides:
|
||||
haproxy:
|
||||
image: docker.io/tripleomaster/centos-binary-haproxy:hotfix
|
||||
@ -209,6 +212,11 @@ containers by Ansible.
|
||||
|
||||
$ ansible-playbook haproxy.yaml --check --diff
|
||||
|
||||
The ``tripleo_container_manage_clean_orphans`` parameter is optional
|
||||
and can be set to `false` to not clean orphaned containers for a
|
||||
config_id. It can be used to manage a single container without
|
||||
impacting other running containers with same config_id.
|
||||
|
||||
The ``tripleo_container_manage_config_overrides`` parameter is optional
|
||||
and can be used to override a specific container attribute like the image
|
||||
or the container user. The parameter takes a dictionary where each key is the
|
||||
|
@ -19,10 +19,6 @@ import json
|
||||
import re
|
||||
import six
|
||||
|
||||
from collections import OrderedDict
|
||||
from operator import itemgetter
|
||||
|
||||
|
||||
# cmp() doesn't exist on python3
|
||||
if six.PY3:
|
||||
def cmp(a, b):
|
||||
@ -98,7 +94,7 @@ class FilterModule(object):
|
||||
return return_dict
|
||||
|
||||
def needs_delete(self, container_infos, config, config_id,
|
||||
clean_orphans=True, check_config=True):
|
||||
clean_orphans=False, check_config=True):
|
||||
"""Returns a list of containers which need to be removed.
|
||||
|
||||
This filter will check which containers need to be removed for these
|
||||
@ -116,15 +112,6 @@ class FilterModule(object):
|
||||
to_skip = []
|
||||
installed_containers = []
|
||||
|
||||
# If config has no item, it's probably due to a user error where
|
||||
# the given pattern match no container.
|
||||
# If config has one item, it's because we want to manage only one
|
||||
# container.
|
||||
# In both cases, we don't want to remove the others in the same
|
||||
# config_id.
|
||||
if len(config) <= 1:
|
||||
clean_orphans = False
|
||||
|
||||
for c in container_infos:
|
||||
c_name = c['Name']
|
||||
installed_containers.append(c_name)
|
||||
|
@ -18,6 +18,7 @@
|
||||
# All variables intended for modification should place placed in this file.
|
||||
tripleo_container_manage_hide_sensitive_logs: "{{ hide_sensitive_logs | default(true) }}"
|
||||
tripleo_container_manage_debug: "{{ ((ansible_verbosity | int) >= 2) | bool }}"
|
||||
tripleo_container_manage_clean_orphans: true
|
||||
|
||||
# All variables within this role should have a prefix of "tripleo_container_manage"
|
||||
tripleo_container_manage_check_puppet_config: false
|
||||
|
@ -207,6 +207,7 @@
|
||||
tripleo_container_manage_config: '/tmp/container-configs'
|
||||
tripleo_container_manage_debug: true
|
||||
tripleo_container_manage_config_patterns: 'fedora.json'
|
||||
tripleo_container_manage_clean_orphans: false
|
||||
tripleo_container_manage_config_overrides:
|
||||
fedora:
|
||||
image: fedora:rawhide
|
||||
@ -258,6 +259,7 @@
|
||||
tripleo_container_manage_config: '/tmp/container-configs'
|
||||
tripleo_container_manage_debug: true
|
||||
tripleo_container_manage_config_patterns: 'feduraaa.json'
|
||||
tripleo_container_manage_clean_orphans: false
|
||||
tasks:
|
||||
- include_role:
|
||||
name: tripleo_container_manage
|
||||
|
@ -33,6 +33,8 @@ provisioner:
|
||||
hosts:
|
||||
instance:
|
||||
ansible_host: localhost
|
||||
ansible_connection: local
|
||||
ansible_distribution: centos8
|
||||
log: true
|
||||
env:
|
||||
ANSIBLE_STDOUT_CALLBACK: yaml
|
||||
|
@ -30,4 +30,5 @@
|
||||
tripleo_container_cli: "{{ tripleo_container_manage_cli }}"
|
||||
tripleo_containers_to_rm: >-
|
||||
{{ podman_containers.containers | needs_delete(config=all_containers_hash,
|
||||
config_id=tripleo_container_manage_config_id, check_config=False) }}
|
||||
config_id=tripleo_container_manage_config_id, check_config=False,
|
||||
clean_orphans=True) }}
|
||||
|
@ -71,5 +71,7 @@
|
||||
- tripleo_container_manage_check_puppet_config|bool
|
||||
- name: "Delete orphan containers from {{ tripleo_container_manage_config }}"
|
||||
include_tasks: delete_orphan.yml
|
||||
when:
|
||||
- tripleo_container_manage_clean_orphans|bool
|
||||
- name: "Create containers from {{ tripleo_container_manage_config }}"
|
||||
include_tasks: create.yml
|
||||
|
@ -24,7 +24,7 @@
|
||||
tripleo_containers_to_rm: >-
|
||||
{{ podman_containers.containers | needs_delete(config=batched_container_data|
|
||||
haskey(attribute='action', reverse=True)|singledict,
|
||||
config_id=tripleo_container_manage_config_id, clean_orphans=False) }}
|
||||
config_id=tripleo_container_manage_config_id) }}
|
||||
|
||||
- name: "Async container create/run"
|
||||
async: "{{ (not ansible_check_mode | bool) | ternary('600', omit) }}"
|
||||
|
@ -488,7 +488,8 @@ class TestHelperFilters(tests_base.TestCase):
|
||||
expected_list = ['rabbitmq', 'haproxy', 'heat', 'test1', 'old_tripleo']
|
||||
result = self.filters.needs_delete(container_infos=data,
|
||||
config=config,
|
||||
config_id='tripleo_step1')
|
||||
config_id='tripleo_step1',
|
||||
clean_orphans=True)
|
||||
self.assertEqual(result, expected_list)
|
||||
|
||||
def test_needs_delete_no_config_check(self):
|
||||
@ -610,7 +611,8 @@ class TestHelperFilters(tests_base.TestCase):
|
||||
result = self.filters.needs_delete(container_infos=data,
|
||||
config=config,
|
||||
config_id='tripleo_step1',
|
||||
check_config=False)
|
||||
check_config=False,
|
||||
clean_orphans=True)
|
||||
self.assertEqual(result, expected_list)
|
||||
|
||||
def test_needs_delete_single_config(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user