From 10dad832eea1dc2aa7507c65171d3af49d5d055e Mon Sep 17 00:00:00 2001 From: Michal Nasiadka Date: Fri, 21 Aug 2026 09:40:06 +0200 Subject: [PATCH] Fix merge_configs/yaml and concat behaviour Closes-Bug: #2164718 Change-Id: I9a7b12c660978f51b6102d58cc64de0d8dc30dd4 Signed-off-by: Michal Nasiadka --- ansible/roles/kolla-openstack/tasks/config.yml | 11 +++++++---- kayobe/plugins/action/merge_configs.py | 6 +++++- kayobe/plugins/action/merge_yaml.py | 6 +++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ansible/roles/kolla-openstack/tasks/config.yml b/ansible/roles/kolla-openstack/tasks/config.yml index ce318fbc6..96cda133d 100644 --- a/ansible/roles/kolla-openstack/tasks/config.yml +++ b/ansible/roles/kolla-openstack/tasks/config.yml @@ -117,12 +117,15 @@ - name: "Ensure extra configuration files exist (strategy: concat)" vars: params: - content: | - {%- for path in item.sources -%} - {{ lookup('file', path) }} - {%- endfor -%} + # join() guarantees exactly one newline between sources, regardless + # of whether a source file ends with one - lookup('file') rstrips + # trailing whitespace from each source, so concatenating without an + # explicit separator can glue the last line of one file to the first + # line of the next. + content: "{{ query('file', *item.sources) | join('\n') }}\n" dest: "{{ item.dest }}" mode: 0640 + lstrip_blocks: true template_content: "{{ params | combine(item.params) }}" with_items: "{{ kolla_custom_config_info.concat }}" diff --git a/kayobe/plugins/action/merge_configs.py b/kayobe/plugins/action/merge_configs.py index 0a93fbfe7..a72f4c122 100644 --- a/kayobe/plugins/action/merge_configs.py +++ b/kayobe/plugins/action/merge_configs.py @@ -167,7 +167,11 @@ def read_config(self, source, config): ] templar = self._templar.copy_with_new_env(searchpath=searchpath) - result = templar.template(template_data) + + # lstrip_blocks avoids Jinja2 block tags (e.g. {% if %}) leaving + # behind leading whitespace that glues adjacent lines together. + result = templar.template( + template_data, overrides=dict(lstrip_blocks=True)) fakefile = StringIO(result) config.parse(fakefile) fakefile.close() diff --git a/kayobe/plugins/action/merge_yaml.py b/kayobe/plugins/action/merge_yaml.py index c35b182b4..ae353191e 100644 --- a/kayobe/plugins/action/merge_yaml.py +++ b/kayobe/plugins/action/merge_yaml.py @@ -107,7 +107,11 @@ def read_config(self, source): ] templar = self._templar.copy_with_new_env(searchpath=searchpath) - template_data = templar.template(template_data) + + # lstrip_blocks avoids Jinja2 block tags (e.g. {% if %}) leaving + # behind leading whitespace that glues adjacent lines together. + template_data = templar.template( + template_data, overrides=dict(lstrip_blocks=True)) result = yaml.safe_load(template_data) return result or {}