Given the list
disk_file:
- [disk1, filename1]
- [disk2, filename2]
- [diskN, filenameN]
join the items. For example,
params: "-x {{ disk_file|map('join', ',file=')|join(' -x ') }}"
gives
params: -x disk1,file=filename1 -x disk2,file=filename2 -x diskN,file=filenameN
Example of a complete playbook for testing
- hosts: localhost
vars:
disk_file:
- [disk1, filename1]
- [disk2, filename2]
- [diskN, filenameN]
params: "-x {{ disk_file|map('join', ',file=')|join(' -x ') }}"
tasks:
- debug:
var: params
- command: echo '{{ params }}'
register: out
- debug:
var: out.stdout
gives
PLAY [localhost] *****************************************************************************
TASK [debug] *********************************************************************************
ok: [localhost] =>
params: -x disk1,file=filename1 -x disk2,file=filename2 -x diskN,file=filenameN
TASK [command] *******************************************************************************
changed: [localhost]
TASK [debug] *********************************************************************************
ok: [localhost] =>
out.stdout: -x disk1,file=filename1 -x disk2,file=filename2 -x diskN,file=filenameN
PLAY RECAP ***********************************************************************************
localhost: ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0