On 2/26/20 8:05 AM, Shifa Shaikh wrote:
> 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

> 
> 
> -- 
> 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] 
> <mailto:[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
> <https://groups.google.com/d/msgid/ansible-project/b857c17b-00f3-44bb-8fd8-4d08f597b6ce%40googlegroups.com?utm_medium=email&utm_source=footer>.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
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/39b0883e-cf0d-8c68-38da-e93d48bc51fd%40linuxia.de.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to