Below is my playbook:
`
-
set_fact:
excludefolders: “{{ excludefolders + ’ -o -name ’ + item | default(‘’) }}”
with_items: “{{ lookup(‘vars’, ‘EXCLUDE_’ + Layer).split(‘,’) }}”
-
debug:
msg: “excludedfolder is {{ excludefolders }}”
`
I get the below output
ok: [10.0.17.113] => { "msg": "excludedfolder is -o -name custom -o -name tree -o -name log"
However i want the variable to have single quotes around item like below:
Expected output:
ok: [10.0.17.113] => { "msg": "excludedfolder is -o -name 'custom' -o -name 'tree' -o -name 'log'"
I tried to use escape charecter for single quotes but none of them worked. Below is what tried.
`
-
set_fact:
excludefolders: “{{ excludefolders + ’ -o -name ’ + ' + item + ' | default(‘’) }}”
with_items: “{{ lookup(‘vars’, ‘EXCLUDE_’ + Layer).split(‘,’) }}”
-
set_fact:
excludefolders: “{{ excludefolders + ’ -o -name ’ ~ ' + item ~ ' | default(‘’) }}”
with_items: “{{ lookup(‘vars’, ‘EXCLUDE_’ + Layer).split(‘,’) }}”
-
set_fact:
excludefolders: “{{ excludefolders + ’ -o -name '’ + item +‘'’ | default(‘’) }}”
with_items: “{{ lookup(‘vars’, ‘EXCLUDE_’ + Layer).split(‘,’) }}”
`
racke
(Stefan Hornburg)
2
Below is my playbook:
>
-set_fact:
excludefolders:"{{ excludefolders + ' -o -name ' + item | default('') }}"
with_items:"{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"
-debug:
msg:"excludedfolder is {{ excludefolders }}"
>
I get the below output
>
ok:[10.0.17.113]=>{"msg":"excludedfolder is -o -name custom -o -name tree -o -name log"
>
However i want the variable to have single quotes around item like below:
Expected output:
>
ok:[10.0.17.113]=>{"msg":"excludedfolder is -o -name 'custom' -o -name 'tree' -o -name 'log'"
>
I tried to use escape charecter for single quotes but none of them worked. Below is what tried.
>
-set_fact:
excludefolders:"{{ excludefolders + ' -o -name ' + \' + item + \' | default('') }}"
with_items:"{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"
-set_fact:
excludefolders:"{{ excludefolders + ' -o -name ' ~ \' + item ~ \' | default('') }}"
with_items:"{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"
-set_fact:
excludefolders:"{{ excludefolders + ' -o -name \'' + item +'\'' | default('') }}"
with_items:"{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"
>
What about the quote filter?
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#id8
Regards
Racke
@Stefan i tried using quote but it does not help. Can you confirm if this is the right way to use quote ? See below:
`
excludefolders: “{{ excludefolders + ’ -o -name ’ + item | quote | default(‘’) }}”
`