tripleo-container-manage: allow to override a container config

Sometimes an operator might want to override a config parameter for a
specific container, without having to rewrite the JSON on the host.

It can now be done with the new
tripleo_container_manage_config_overrides parameter.

Example:

tripleo_container_manage_config_override:
  mysql:
    image: myregistry.io/tripleomaster/haproxy:latest

It introduces a new attribute to the singledict() filter and its unit
test.

Change-Id: If65fcf25c9e07174b08e44539b0501615b6c72ab
This commit is contained in:
Emilien Macchi 2020-01-08 21:35:20 -05:00
parent e55bf76b32
commit 1b84159cc4
4 changed files with 44 additions and 2 deletions

View File

@ -68,15 +68,21 @@ class FilterModule(object):
ordered_dict[o] = v
return ordered_dict
def singledict(self, list_to_convert):
def singledict(self, list_to_convert, merge_with={}):
"""Generate a single dictionary from a list of dictionaries.
This filter will return a single dictionary from a list of
dictionaries.
If merge_with is set, the return dict will be merged with it.
"""
return_dict = {}
for i in list_to_convert:
return_dict.update(i)
for k in merge_with.keys():
if k in return_dict:
for mk, mv in merge_with[k].items():
return_dict[k][mk] = mv
break
return return_dict
def needs_delete(self, container_infos, config, config_id):

View File

@ -22,6 +22,7 @@ tripleo_container_manage_cli: podman
tripleo_container_manage_concurrency: 1
tripleo_container_manage_config: "/var/lib/tripleo-config/"
tripleo_container_manage_config_id: tripleo
tripleo_container_manage_config_overrides: {}
tripleo_container_manage_config_patterns: 'hashed-*.json'
tripleo_container_manage_debug: false
tripleo_container_manage_healthcheck_disabled: false

View File

@ -74,7 +74,9 @@
loop: "{{ container_hashes.results }}"
- name: Finalise hashes for all containers
set_fact:
all_containers_hash: "{{ container_hashes.results | map(attribute='ansible_facts.container_hash') | list | singledict() }}"
all_containers_hash: >-
{{ container_hashes.results | map(attribute='ansible_facts.container_hash') |
list | singledict(merge_with=tripleo_container_manage_config_overrides) }}
- name: "Manage systemd shutdown files"
become: true

View File

@ -125,6 +125,39 @@ class TestHelperFilters(tests_base.TestCase):
result = self.filters.singledict(list)
self.assertEqual(result, expected_dict)
def test_singledict_with_merge(self):
list = [
{
'keystone': {
'start_order': 1,
'image': 'quay.io/tripleo/keystone'
},
},
{
'mysql': {
'start_order': 0,
'image': 'quay.io/tripleo/mysql'
}
}
]
expected_dict = {
'keystone': {
'start_order': 1,
'image': 'quay.io/tripleo/keystone'
},
'mysql': {
'start_order': 0,
'image': 'quay.io/tripleo/mysql:hotfix'
}
}
override = {
'mysql': {
'image': 'quay.io/tripleo/mysql:hotfix'
}
}
result = self.filters.singledict(list, merge_with=override)
self.assertEqual(result, expected_dict)
def test_list_of_keys(self):
keys = [
{