diff --git a/ansible/roles/kolla-openstack/action_plugins/kolla_custom_config_info.py b/ansible/roles/kolla-openstack/action_plugins/kolla_custom_config_info.py index f5ad15429780dc63477c8ad9a308f80f0babbe35..b58b679e14c024788b729787ed5e3d4e1a6a4e0b 100644 --- a/ansible/roles/kolla-openstack/action_plugins/kolla_custom_config_info.py +++ b/ansible/roles/kolla-openstack/action_plugins/kolla_custom_config_info.py @@ -77,13 +77,27 @@ class ConfigCollector(object): result = set(self.files_in_destination) - ignored return list(result) - def _find_matching_rule(self, relative_path): + def _find_matching_rule(self, relative_path, sources): # First match wins for rule in self.rules: if not rule.get('enabled', True): continue glob_ = rule["glob"] if glob.globmatch(relative_path, glob_, flags=glob.GLOBSTAR): + requires_merge = (rule["strategy"] in + ["merge_configs", "merge_yaml"]) + # Fallback to templating when there is only one source. This + # allows you to have config files that template to invalid + # yaml/ini. This was allowed prior to config merging so + # improves backwards compatibility. + if requires_merge and len(sources) == 1: + # The rule can be used again to match a different file + # so don't modify in place. + rule = rule.copy() + rule["strategy"] = 'template' + # Strip parameters as they may not be compatible with + # template module. + rule['params'] = {} return rule def partition_into_actions(self): @@ -114,7 +128,7 @@ class ConfigCollector(object): if not os.path.exists(dirname): missing_directories.add(dirname) - rule = self._find_matching_rule(relative_path) + rule = self._find_matching_rule(relative_path, sources) if not rule: continue diff --git a/releasenotes/notes/fallback-to-templating-when-only-one-source-exists-5eb19c0f6b8820d5.yaml b/releasenotes/notes/fallback-to-templating-when-only-one-source-exists-5eb19c0f6b8820d5.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6edcb55cabd513238e54bf7ca41db27ec66f5bfa --- /dev/null +++ b/releasenotes/notes/fallback-to-templating-when-only-one-source-exists-5eb19c0f6b8820d5.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + When merging kolla config, fallback to templating when only one source file + exists. This allows you to use config that templates to invalid yaml/ini as + long as there isn't an environment override. This improves backwards + compatability where it was permitted to use such constructs.