I have a variable that looks something like this:
files:
- a.yaml
- b.yaml
- c.yaml
Using the ansible.builtin.template module, I'd like to build a file which contains the following string:
OPTIONS="--config=a.yaml --config=b.yaml --config.yaml"
I can't hard-code this as I don't always know:
- How many files there will actually be
- What the names of the files will be
...because they may be set via any one of Ansible's variable setting options (host|group_vars, role defaults etc.). This means I need to "build" it up and then "inject" it into a template somehow.
Is there a way to build up a string from a list like this?
Thanks!
You can achieve this by using the join filter in Ansible.
Here i provide an example playbook that demonstrates how you can build your desired string from the list of files (not limited to 3 files) using the join filter:
Now, you can use the "options_string" variable in your template module or other tasks as you need