Я хочу преобразовать эту переменную:
default_attr:
attr1 :
- "1"
nexatt :
- "b"
...
в "attr = 1, nextattr = b, ..." (строка, разделенная i.e.comma) с использованием шаблона Jinja. Есть ли способ сделать это?
- name: Reading the attributes
set_fact:
app_attributes: |
{% set attributes = " " -%}
{% for key in default_attr.keys() -%}
{% for value in default_attr[key] -%}
{% attributes: "{{ attributes }} + [{'key=value'}]" -%}
{%- endfor %}
{%- endfor %}
{{ attributes }}
Ошибка, которую я получаю, показана ниже:
fatal: [dev1]: FAILED! => {"msg": "template error while templating string: Encountered unknown tag 'attributes'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.. String: {% set attributes = \" \" -%}\n{% for key in default_attr.keys() -%}\n {% for value in default_attr[key] -%}\n {% attributes: \"{{ attributes }} + [{'key=value'}]\" -%}\n {%- endfor %}\n{%- endfor %}\n{{ attributes }}\n"}
Есть ли способ построить эту строку с помощью Jinja?