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(',') }}"




-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b857c17b-00f3-44bb-8fd8-4d08f597b6ce%40googlegroups.com.

Reply via email to