I have a specific ansible variable structure that I want to get from the vault into a yaml file on my hosts.
Lets assume a structure like this:
secrets:
psp1:
username: this
password: that
secret_key: 123
...
I need something like a "generic" template to output whatever "secrets" contains at the moment, since the content changes almost completely based on the current environment.
The easiest solution I can think of is to output the whole structure in an template like this:
# config/secrets.yml
{{ secrets | to_yaml }}
But the jinja2 to_yaml filter does only "yamlify" the first level, deeper nestings are outputted in json.
Can I work around that problem somehow? Is there an easier way to achieve what I want?
Thanks for any help!
to_yaml
(instead ofto_nice_yaml
) you have fairly old install of ansible, it's time to upgrade.to_nice_yaml
It's possible to pass your own kwargs to filter functions, which usually pass them on to underlying python module call. Like this one for your case. So something like:
only catch is you can't override
indent=4, allow_unicode=True, default_flow_style=False