You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
976 B
976 B
| title | date | opensource | topics |
|---|---|---|---|
| Ansible: Add a prefix or suffix to all items of a list | 2019-11-18T00:00:00+02:00 | [Ansible] | [IT Automation] |
Recently, in one of my Ansible playbooks I had to prefix all items of a list with a chosen string.
Namely, from the following list:
[ "bar", "bat", "baz" ]
I want to have:
[ "foobar", "foobat", "foobaz" ]
The recipe I used to add a prefix to all items of a list is:
- debug:
var: result
vars:
prefix: foo
a_list: [ "bar", "bat", "baz" ]
result: "{{ [prefix] | product(a_list) | map('join') | list }}"
If you need to add a suffix to all items of a list instead, you can use:
- debug:
var: result
vars:
suffix: foo
a_list: [ "bar", "bat", "baz" ]
result: "{{ a_list | product([suffix]) | map('join') | list }}"