Adding graceful failure condition to options dictionary lookup

Patch also refactors the 'Building list of replaceable data' task
to use less jinja templating, in favor of ansible syntax.

Additional debug statements were implemented to provide more
detailed overview of the process.

Resolves: rhbz#2150298

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I0b77c6e8116629f0b3f7c54c2f4dab0f0ab040bf
(cherry picked from commit da4fe922e3)
This commit is contained in:
Jiri Podivin 2022-12-05 15:22:38 +01:00
parent f1fa768f33
commit 27fe445486
1 changed files with 52 additions and 20 deletions

View File

@ -37,29 +37,61 @@
var: opt_val
- name: Building list of replaceable data
vars:
templates: []
sections: []
when:
- opt_data | length
- "('index_key' in option_data and opt_val.value) or 'group_create' in option_data"
set_fact:
new_sections: >-
{% set section_list = {} %}{%
set templates = [] %}{%
if 'template_section' in option_data %}{%
for section in option_data.template_section %}{%
set _ = templates.extend(opt_data.options[section].opts) %}{%
endfor %}{%
if 'separator' in option_data.index_key %}{%
set sections = opt_val.value.split(option_data.index_key.separator) | list %}{%
else %}{%
set sections = [opt_val.value] %}{%
endif %}{%
elif 'group_create' in option_data %}{%
set _ = templates.extend(opt_data.options[option_data.group_create.template].opts) %}{%
set sections = [option_data.group_create.group_name] %}{%
endif %}{%
for val in sections %}{%
set _ = section_list.__setitem__(val, {"opts": templates }) %}{%
endfor %}{{ section_list }}
block:
- name: Printing opt_data.options
debug:
var: opt_data.options
when: oslo_config_validator_debug | bool
- name: Printing option_data
debug:
var: option_data
when: oslo_config_validator_debug | bool
- block:
- name: Populating templates list
set_fact:
templates: "{{ templates + [ opt_data.options[item].opts ] }}"
with_items: "{{ option_data.template_section }}"
- name: Populating sections list with separator
set_fact:
sections: "{{ opt_val.value | split(option_data.index_key.separator) | list}}"
when: "{{ 'separator' in option_data.index_key }}"
- name: Populating sections list without separator
set_fact:
sections: "{{ [opt_val.value] }}"
when: "{{ 'separator' not in option_data.index_key }}"
when: "{{ 'template_section' in option_data }}"
- block:
- fail:
msg: >
Requested template key {{ option_data.group_create.template }} isn't
present in the options data dictionary.
{{ opt_data.options }}
when: option_data.group_create.template not in opt_data.options
- name: Populating sections and templates list without template_section
set_fact:
templates: "{{ opt_data.options[option_data.group_create.template].opts }}"
sections: "{{ [option_data.group_create.group_name] }}"
when: "{{ 'group_create' in option_data and 'template_section' not in option_data }}"
- name: Printing sections
debug:
var: sections
when: oslo_config_validator_debug | bool
- set_fact:
new_sections: >-
{% set section_list = {} %}{%
for val in sections %}{%
set _ = section_list.__setitem__(val, {"opts": templates }) %}{%
endfor %}{{ section_list }}
- name: Printing generated sections
when: