Ansible write variables into YAML file

后端 未结 1 737
抹茶落季
抹茶落季 2021-02-04 06:48

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:
         


        
相关标签:
1条回答
  • 2021-02-04 07:37
    1. As jwodder said, it's valid.

    2. If you're using to_yaml (instead of to_nice_yaml) you have fairly old install of ansible, it's time to upgrade.

    3. Use to_nice_yaml

    4. 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:

       {{ secrets | to_nice_yaml( width=50, explicit_start=True, explicit_end=True) }}
      

    only catch is you can't override indent=4, allow_unicode=True, default_flow_style=False

    Note that indent can now be overridden, at least as of Ansible 2.2.0 (I use it to indent 2 spaces to follow coding standards for one project).

    Better documentation for to_nice_yaml can be found here.

    0 讨论(0)
提交回复
热议问题