Hi there,
I’ve been trying to do something I think I already saw done, but I can’t get it to work: I want to parse an inline template into a variable.
Everything I find is either to file (ansible.builtin.template
task), template lookup from a template file, or just mentions regular {{ var }}
templates, which are obvious, but I need loops and the fancy bits of jinja :-p
In essence, I have a nested dict:
config:
default:
instance: prodbox
auth:
admin_user: francis
admin_password: heloveshismomandcatandpancakes
database:
type: mysql
schema: pancake
user: mom
password: kitty99
And I need to build that into a bunch of individual lines in a variable that basically flatten the structure.
I’ve tried a million variations of this task:
- ansible.builtin.set_fact:
config_blob: |-
{% for section, conf in config %}
{% for key, value in conf %}
{{ 'GF_' + section | upper + '_' + key | upper + '=' + value }}
{% endfor %}
{% endfor %}
but depending on the variation, I get errors about unexpected % signs, something not being able to convert to dict or list, etc.
Any help would be appreciated. Being told that my memory is broken and it totally isn’t possible is less fun but would at least put me at rest to find a less elegant solution with tempfiles