Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Stefan Hornburg (Racke)
On 3/6/20 1:35 PM, Shifa Shaikh wrote:
> I know how to lookup a file using fileglob in Ansible but not sure how to 
> inside a Jinja template.
> 

Very simple:

{% if lookup('fileglob', '/home/racke/tmp/*.txt') %}

Regards
Racke

> On Fri, 6 Mar, 2020, 5:55 pm Stefan Hornburg (Racke),  > wrote:
> 
> On 3/6/20 1:12 PM, Shifa Shaikh wrote:
> > @Stefan I wish to check if the file bad*.txt exists on the path. Based 
> on the if condition I wish to template
> different
> >  output.
> 
> I assume that you are checking for file names matching bad*.txt. In that 
> case you can use the fileglob lookup:
> 
> https://docs.ansible.com/ansible/latest/plugins/lookup/fileglob.html
> 
> Regards
>           Racke
> 
> >
> > On Fri, 6 Mar, 2020, 5:34 pm Stefan Hornburg (Racke),  
> >> wrote:
> >
> >     On 3/6/20 12:52 PM, Shifa Shaikh wrote:
> >     > @Stefan I tried you suggestion of not using the curly braces and 
> it helped resolve the error. But now i get
> a new
> >     error.
> >     >
> >     > |
> >     > {%ifplaybook_dir +'/'+item +'/'+'bad*.txt'|exists %}
> >     > |
> >
> >
> >     There is no filter named 'exists'. Please explain what you want to 
> achieve with this template.
> >
> >     Regards
> >              Racke
> >
> >     >
> >     > TASK [Create the Jinja2 based template]
> >     >
> 
> *
> >     > fatal: [localhost]: FAILED! => {"changed": false, "msg": 
> "AnsibleError: template error while templating
> string: no
> >     > filter named 'exists'. 
> >     >
> >     > Looks like the issue is with "exists" filter.
> >     >
> >     > On Friday, March 6, 2020 at 5:13:26 PM UTC+5:30, Stefan Hornburg 
> (Racke) wrote:
> >     >
> >     >     On 3/6/20 11:52 AM, Shifa Shaikh wrote:
> >     >     > Vladimir Hi, 
> >     >     >
> >     >     > I tried 
> >     >     >
> >     >     > |
> >     >     > {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %}
> >     >     >
> >     >
> >     >     Don't use the curly braces inside the {%if ... } condition:
> >     >
> >     >     {% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %}
> >     >
> >     >     Regards
> >     >               Racke
> >     >
> >     >     >
> >     >     > {{item }}
> >     >     >
> >     >     >
> >     >     >
> >     >     > {%else%}
> >     >     >
> >     >     >
> >     >     > {{item }}
> >     >     >
> >     >     >
> >     >     >
> >     >     > {%endif %}
> >     >     >
> >     >     > |
> >     >     >
> >     >     > But I get this error:
> >     >     >
> >     >     > |
> >     >     > TASK [Createthe Jinja2based
> >     >     >
> >     >   
> >   
>   
> template]*
> >     >
> >     >     > 
> fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: template 
> error while templating string:
> >     expected
> >     >     token
> >     >     > ':', got '}'. String: {% for layer in layers %}\n
> >     >     > |
> >     >     >
> >     >     >
> >     >     >
> >     >     >
> >     >     > On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir 
> Botka wrote:
> >     >     >
> >     >     >     On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
> >     >     >     Shifa Shaikh    > > wrote:
> >     >     >
> >     >     >     > How do i  put the if /else condition in the jinja 
> template ?
> >     >     >
> >     >     >     See "if"
> >     >     >     
> https://jinja.palletsprojects.com/en/2.11.x/templates/#if
> >     >     
> >     >      >     >
> >     >     >
> >     >     >
> >     >     > --
> >     >     > 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
> >     >     > ansible...@googlegroups.com 
>   > 
> >      

Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
I know how to lookup a file using fileglob in Ansible but not sure how to
inside a Jinja template.

On Fri, 6 Mar, 2020, 5:55 pm Stefan Hornburg (Racke), 
wrote:

> On 3/6/20 1:12 PM, Shifa Shaikh wrote:
> > @Stefan I wish to check if the file bad*.txt exists on the path. Based
> on the if condition I wish to template different
> >  output.
>
> I assume that you are checking for file names matching bad*.txt. In that
> case you can use the fileglob lookup:
>
> https://docs.ansible.com/ansible/latest/plugins/lookup/fileglob.html
>
> Regards
>   Racke
>
> >
> > On Fri, 6 Mar, 2020, 5:34 pm Stefan Hornburg (Racke),  > wrote:
> >
> > On 3/6/20 12:52 PM, Shifa Shaikh wrote:
> > > @Stefan I tried you suggestion of not using the curly braces and
> it helped resolve the error. But now i get a new
> > error.
> > >
> > > |
> > > {%ifplaybook_dir +'/'+item +'/'+'bad*.txt'|exists %}
> > > |
> >
> >
> > There is no filter named 'exists'. Please explain what you want to
> achieve with this template.
> >
> > Regards
> >  Racke
> >
> > >
> > > TASK [Create the Jinja2 based template]
> > >
> *
> > > fatal: [localhost]: FAILED! => {"changed": false, "msg":
> "AnsibleError: template error while templating string: no
> > > filter named 'exists'.
> > >
> > > Looks like the issue is with "exists" filter.
> > >
> > > On Friday, March 6, 2020 at 5:13:26 PM UTC+5:30, Stefan Hornburg
> (Racke) wrote:
> > >
> > > On 3/6/20 11:52 AM, Shifa Shaikh wrote:
> > > > Vladimir Hi,
> > > >
> > > > I tried
> > > >
> > > > |
> > > > {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %}
> > > >
> > >
> > > Don't use the curly braces inside the {%if ... } condition:
> > >
> > > {% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %}
> > >
> > > Regards
> > >   Racke
> > >
> > > >
> > > > {{item }}
> > > >
> > > >
> > > >
> > > > {%else%}
> > > >
> > > >
> > > > {{item }}
> > > >
> > > >
> > > >
> > > > {%endif %}
> > > >
> > > > |
> > > >
> > > > But I get this error:
> > > >
> > > > |
> > > > TASK [Createthe Jinja2based
> > > >
> > >
> >
>   
> template]*
> > >
> > > >
> fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: template
> error while templating string:
> > expected
> > > token
> > > > ':', got '}'. String: {% for layer in layers %}\n
> > > > |
> > > >
> > > >
> > > >
> > > >
> > > > On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir
> Botka wrote:
> > > >
> > > > On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
> > > > Shifa Shaikh  shif...@gmail.com> > wrote:
> > > >
> > > > > How do i  put the if /else condition in the jinja
> template ?
> > > >
> > > > See "if"
> > > >
> https://jinja.palletsprojects.com/en/2.11.x/templates/#if
> > > 
> > >  > >
> > > >
> > > >
> > > > --
> > > > 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
> > > > ansible...@googlegroups.com  ansible...@googlegroups.com> 
> > 
> > >.
> > > > To view this discussion on the web visit
> > > >
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> > > <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> >
> > > >
> > >
> >  <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_source=footer
> > >
> >  <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_source=footer
> >>.
> > >
> > >
> > >
> > > --
> > > Ecommerce and Linux consulting + Perl and web application
> programming.
> > > Debian and Sympa administration. 

Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Stefan Hornburg (Racke)
On 3/6/20 1:12 PM, Shifa Shaikh wrote:
> @Stefan I wish to check if the file bad*.txt exists on the path. Based on the 
> if condition I wish to template different
>  output.

I assume that you are checking for file names matching bad*.txt. In that case 
you can use the fileglob lookup:

https://docs.ansible.com/ansible/latest/plugins/lookup/fileglob.html

Regards
  Racke

> 
> On Fri, 6 Mar, 2020, 5:34 pm Stefan Hornburg (Racke),  > wrote:
> 
> On 3/6/20 12:52 PM, Shifa Shaikh wrote:
> > @Stefan I tried you suggestion of not using the curly braces and it 
> helped resolve the error. But now i get a new
> error.
> >
> > |
> > {%ifplaybook_dir +'/'+item +'/'+'bad*.txt'|exists %}
> > |
> 
> 
> There is no filter named 'exists'. Please explain what you want to 
> achieve with this template.
> 
> Regards
>          Racke
> 
> >
> > TASK [Create the Jinja2 based template]
> > 
> *
> > fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError: 
> template error while templating string: no
> > filter named 'exists'. 
> >
> > Looks like the issue is with "exists" filter.
> >
> > On Friday, March 6, 2020 at 5:13:26 PM UTC+5:30, Stefan Hornburg 
> (Racke) wrote:
> >
> >     On 3/6/20 11:52 AM, Shifa Shaikh wrote:
> >     > Vladimir Hi, 
> >     >
> >     > I tried 
> >     >
> >     > |
> >     > {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %}
> >     >
> >
> >     Don't use the curly braces inside the {%if ... } condition:
> >
> >     {% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %}
> >
> >     Regards
> >               Racke
> >
> >     >
> >     > {{item }}
> >     >
> >     >
> >     >
> >     > {%else%}
> >     >
> >     >
> >     > {{item }}
> >     >
> >     >
> >     >
> >     > {%endif %}
> >     >
> >     > |
> >     >
> >     > But I get this error:
> >     >
> >     > |
> >     > TASK [Createthe Jinja2based
> >     >
> >   
>  
> template]*
> >
> >     > fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: 
> template error while templating string:
> expected
> >     token
> >     > ':', got '}'. String: {% for layer in layers %}\n
> >     > |
> >     >
> >     >
> >     >
> >     >
> >     > On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka 
> wrote:
> >     >
> >     >     On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
> >     >     Shifa Shaikh mailto:shif...@gmail.com> 
> > wrote:
> >     >
> >     >     > How do i  put the if /else condition in the jinja template ?
> >     >
> >     >     See "if"
> >     >     https://jinja.palletsprojects.com/en/2.11.x/templates/#if
> >     
> >      >
> >     >
> >     >
> >     > --
> >     > 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
> >     > ansible...@googlegroups.com  
> 
>  
> >.
> >     > To view this discussion on the web visit
> >     > 
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> >     
> 
> >     >
> >   
>  
>  >   
>  
> >.
> >
> >
> >
> >     --
> >     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
> > ansible-project+unsubscr...@googlegroups.com 
> 

Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
@Stefan I wish to check if the file bad*.txt exists on the path. Based on
the if condition I wish to template different  output.

On Fri, 6 Mar, 2020, 5:34 pm Stefan Hornburg (Racke), 
wrote:

> On 3/6/20 12:52 PM, Shifa Shaikh wrote:
> > @Stefan I tried you suggestion of not using the curly braces and it
> helped resolve the error. But now i get a new error.
> >
> > |
> > {%ifplaybook_dir +'/'+item +'/'+'bad*.txt'|exists %}
> > |
>
>
> There is no filter named 'exists'. Please explain what you want to achieve
> with this template.
>
> Regards
>  Racke
>
> >
> > TASK [Create the Jinja2 based template]
> >
> *
> > fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError:
> template error while templating string: no
> > filter named 'exists'.
> >
> > Looks like the issue is with "exists" filter.
> >
> > On Friday, March 6, 2020 at 5:13:26 PM UTC+5:30, Stefan Hornburg (Racke)
> wrote:
> >
> > On 3/6/20 11:52 AM, Shifa Shaikh wrote:
> > > Vladimir Hi,
> > >
> > > I tried
> > >
> > > |
> > > {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %}
> > >
> >
> > Don't use the curly braces inside the {%if ... } condition:
> >
> > {% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %}
> >
> > Regards
> >   Racke
> >
> > >
> > > {{item }}
> > >
> > >
> > >
> > > {%else%}
> > >
> > >
> > > {{item }}
> > >
> > >
> > >
> > > {%endif %}
> > >
> > > |
> > >
> > > But I get this error:
> > >
> > > |
> > > TASK [Createthe Jinja2based
> > >
> >
>  
> template]*
> >
> > > fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError:
> template error while templating string: expected
> > token
> > > ':', got '}'. String: {% for layer in layers %}\n
> > > |
> > >
> > >
> > >
> > >
> > > On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka
> wrote:
> > >
> > > On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
> > > Shifa Shaikh > wrote:
> > >
> > > > How do i  put the if /else condition in the jinja template ?
> > >
> > > See "if"
> > > https://jinja.palletsprojects.com/en/2.11.x/templates/#if
> > 
> >  https://jinja.palletsprojects.com/en/2.11.x/templates/#if>>
> > >
> > >
> > > --
> > > 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
> > > ansible...@googlegroups.com   ansible-project+unsubscr...@googlegroups.com >.
> > > To view this discussion on the web visit
> > >
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> >
> > >
> > <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_source=footer
> > <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_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
> > ansible-project+unsubscr...@googlegroups.com  ansible-project+unsubscr...@googlegroups.com>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/d22c2c58-3d3c-4cb6-8119-662a1a2e52ea%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/d22c2c58-3d3c-4cb6-8119-662a1a2e52ea%40googlegroups.com?utm_medium=email_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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/a7f0c40f-a98e-58e2-c659-c10b283bddf0%40linuxia.de
> .
>

-- 
You received this message because you 

Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Stefan Hornburg (Racke)
On 3/6/20 12:52 PM, Shifa Shaikh wrote:
> @Stefan I tried you suggestion of not using the curly braces and it helped 
> resolve the error. But now i get a new error.
> 
> |
> {%ifplaybook_dir +'/'+item +'/'+'bad*.txt'|exists %}
> |


There is no filter named 'exists'. Please explain what you want to achieve with 
this template.

Regards
 Racke

> 
> TASK [Create the Jinja2 based template]
> *
> fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError: 
> template error while templating string: no
> filter named 'exists'. 
> 
> Looks like the issue is with "exists" filter.
> 
> On Friday, March 6, 2020 at 5:13:26 PM UTC+5:30, Stefan Hornburg (Racke) 
> wrote:
> 
> On 3/6/20 11:52 AM, Shifa Shaikh wrote:
> > Vladimir Hi, 
> >
> > I tried 
> >
> > |
> > {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %}
> >
> 
> Don't use the curly braces inside the {%if ... } condition:
> 
> {% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %}
> 
> Regards
>           Racke
> 
> >
> > {{item }}
> >
> >
> >
> > {%else%}
> >
> >
> > {{item }}
> >
> >
> >
> > {%endif %}
> >
> > |
> >
> > But I get this error:
> >
> > |
> > TASK [Createthe Jinja2based
> >
> 
> template]*
> 
> > fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: 
> template error while templating string: expected
> token
> > ':', got '}'. String: {% for layer in layers %}\n
> > |
> >
> >
> >
> >
> > On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote:
> >
> >     On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
> >     Shifa Shaikh > wrote:
> >
> >     > How do i  put the if /else condition in the jinja template ?
> >
> >     See "if"
> >     https://jinja.palletsprojects.com/en/2.11.x/templates/#if
> 
>  >
> >
> >
> > --
> > 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
> > ansible...@googlegroups.com  
> .
> > To view this discussion on the web visit
> > 
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> 
> 
> >
> 
>  
> >.
> 
> 
> 
> -- 
> 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
> ansible-project+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/d22c2c58-3d3c-4cb6-8119-662a1a2e52ea%40googlegroups.com
> .


-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a7f0c40f-a98e-58e2-c659-c10b283bddf0%40linuxia.de.


signature.asc
Description: OpenPGP digital signature


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
@Stefan I tried you suggestion of not using the curly braces and it helped 
resolve the error. But now i get a new error.

{% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %}


TASK [Create the Jinja2 based template] 
*
fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError: 
template error while templating string: no filter named 'exists'. 

Looks like the issue is with "exists" filter.

On Friday, March 6, 2020 at 5:13:26 PM UTC+5:30, Stefan Hornburg (Racke) 
wrote:
>
> On 3/6/20 11:52 AM, Shifa Shaikh wrote: 
> > Vladimir Hi,  
> > 
> > I tried  
> > 
> > | 
> > {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %} 
> > 
>
> Don't use the curly braces inside the {%if ... } condition: 
>
> {% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %} 
>
> Regards 
>   Racke 
>
> > 
> > {{item }} 
> > 
> > 
> > 
> > {%else%} 
> > 
> > 
> > {{item }} 
> > 
> > 
> > 
> > {%endif %} 
> > 
> > | 
> > 
> > But I get this error: 
> > 
> > | 
> > TASK [Createthe Jinja2based 
> > 
> template]*
>  
>
> > fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: 
> template error while templating string: expected token 
> > ':', got '}'. String: {% for layer in layers %}\n 
> > | 
> > 
> > 
> > 
> > 
> > On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote: 
> > 
> > On Fri, 6 Mar 2020 01:59:00 -0800 (PST) 
> > Shifa Shaikh > wrote: 
> > 
> > > How do i  put the if /else condition in the jinja template ? 
> > 
> > See "if" 
> > https://jinja.palletsprojects.com/en/2.11.x/templates/#if <
> https://jinja.palletsprojects.com/en/2.11.x/templates/#if> 
> > 
> > 
> > -- 
> > 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 
> > ansible...@googlegroups.com   ansible-project+unsubscr...@googlegroups.com >. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d22c2c58-3d3c-4cb6-8119-662a1a2e52ea%40googlegroups.com.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
@Stefan sorry but I could not understand your statement. 

Are you asking me to move the if statement out of the jinja template ?

Below is the complete jinja template with the if statement that errors. I'm 
able to populate all the values correctly and the playbook works fine when 
the if statement is removed from the jinja template. 

{% for layer in layers %}


 
{% for item in layer.things %}

{% if {{ playbook_dir }}/{{ item }}/bad*.txt | exists %}
{{ item }}

{% else %}
{{ item }}

{% endif %}

{% endfor %}


{% endfor %}

On Friday, March 6, 2020 at 5:08:37 PM UTC+5:30, Stefan Hornburg (Racke) 
wrote:
>
> On 3/6/20 12:02 PM, Jean-Yves LENHOF wrote: 
> > Hi, 
> > 
> > Your error is about a for loop, but your template included in your email 
> doesn't have this loop. 
>
> The loop could be applied to the task, in that case you can use {{ item }} 
> in the template on its own. 
>
> Regards 
>  Racke 
>
> > 
> > Looks like you didn't give us the good one 
> > 
> > Regards, 
> > 
> > JYL 
> > 
> > 
> > Le 06/03/2020 à 11:52, Shifa Shaikh a écrit : 
> >> Vladimir Hi,  
> >> 
> >> I tried  
> >> 
> >> | 
> >> {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %} 
> >> 
> >> 
> >> {{item }} 
> >> 
> >> 
> >> 
> >> {%else%} 
> >> 
> >> 
> >> {{item }} 
> >> 
> >> 
> >> 
> >> {%endif %} 
> >> 
> >> | 
> >> 
> >> But I get this error: 
> >> 
> >> | 
> >> TASK [Createthe Jinja2based 
> >> 
> template]*
>  
>
> >> fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: 
> template error while templating string: expected 
> >> token ':', got '}'. String: {% for layer in layers %}\n 
> >> | 
> >> 
> >> 
> >> 
> >> 
> >> On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote: 
> >> 
> >> On Fri, 6 Mar 2020 01:59:00 -0800 (PST) 
> >> Shifa Shaikh > wrote: 
> >> 
> >> > How do i  put the if /else condition in the jinja template ? 
> >> 
> >> See "if" 
> >> https://jinja.palletsprojects.com/en/2.11.x/templates/#if <
> https://jinja.palletsprojects.com/en/2.11.x/templates/#if> 
> >> 
> >> 
> >> -- 
> >> 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 
> >> ansible...@googlegroups.com   ansible-project+unsubscr...@googlegroups.com >. 
> >> To view this discussion on the web visit 
> >> 
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
>  
> >> <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_source=footer>.
>  
>
> > 
> > -- 
> > 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 
> > ansible...@googlegroups.com   ansible-project+unsubscr...@googlegroups.com >. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/ansible-project/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org
>  
> > <
> https://groups.google.com/d/msgid/ansible-project/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org?utm_medium=email_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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fc1f3a81-c882-4b57-9644-8341ac95500c%40googlegroups.com.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Stefan Hornburg (Racke)
On 3/6/20 11:52 AM, Shifa Shaikh wrote:
> Vladimir Hi, 
> 
> I tried 
> 
> |
> {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %}
> 

Don't use the curly braces inside the {%if ... } condition:

{% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %}

Regards
  Racke

> 
> {{item }}
> 
> 
> 
> {%else%}
> 
> 
> {{item }}
> 
> 
> 
> {%endif %}
> 
> |
> 
> But I get this error:
> 
> |
> TASK [Createthe Jinja2based
> template]*
> fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: template 
> error while templating string: expected token
> ':', got '}'. String: {% for layer in layers %}\n
> |
> 
> 
> 
> 
> On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote:
> 
> On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
> Shifa Shaikh > wrote:
> 
> > How do i  put the if /else condition in the jinja template ?
> 
> See "if"
> https://jinja.palletsprojects.com/en/2.11.x/templates/#if 
> 
> 
> 
> -- 
> 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
> ansible-project+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> .


-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3e915c0e-3af7-5150-64a7-a41e09b94eea%40linuxia.de.


signature.asc
Description: OpenPGP digital signature


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Stefan Hornburg (Racke)
On 3/6/20 12:02 PM, Jean-Yves LENHOF wrote:
> Hi,
> 
> Your error is about a for loop, but your template included in your email 
> doesn't have this loop.

The loop could be applied to the task, in that case you can use {{ item }} in 
the template on its own.

Regards
 Racke

> 
> Looks like you didn't give us the good one
> 
> Regards,
> 
> JYL
> 
> 
> Le 06/03/2020 à 11:52, Shifa Shaikh a écrit :
>> Vladimir Hi, 
>>
>> I tried 
>>
>> |
>> {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %}
>>
>>
>> {{item }}
>>
>>
>>
>> {%else%}
>>
>>
>> {{item }}
>>
>>
>>
>> {%endif %}
>>
>> |
>>
>> But I get this error:
>>
>> |
>> TASK [Createthe Jinja2based
>> template]*
>> fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: template 
>> error while templating string: expected
>> token ':', got '}'. String: {% for layer in layers %}\n
>> |
>>
>>
>>
>>
>> On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote:
>>
>> On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
>> Shifa Shaikh > wrote:
>>
>> > How do i  put the if /else condition in the jinja template ?
>>
>> See "if"
>> https://jinja.palletsprojects.com/en/2.11.x/templates/#if 
>> 
>>
>>
>> -- 
>> 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
>> ansible-project+unsubscr...@googlegroups.com 
>> .
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
>> .
> 
> -- 
> 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
> ansible-project+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org
> .


-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0a47f2df-0881-159b-8415-86a6e61110ef%40linuxia.de.


signature.asc
Description: OpenPGP digital signature


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
Jean hi,

I incorporated the if statement from my previous post in my original Jinja
template after the second 'for loop' in my original post.

Once the if condition is removed the error does not show anymore.

On Fri, 6 Mar, 2020, 4:33 pm Jean-Yves LENHOF, 
wrote:

> Hi,
>
> Your error is about a for loop, but your template included in your email
> doesn't have this loop.
>
> Looks like you didn't give us the good one
>
> Regards,
>
> JYL
>
>
> Le 06/03/2020 à 11:52, Shifa Shaikh a écrit :
>
> Vladimir Hi,
>
> I tried
>
> {% if {{ playbook_dir }}/{{ item }}/bad*.txt | exists %}
>
>
> {{ item }}
>
>
>
> {% else %}
>
>
> {{ item }}
>
>
>
> {% endif %}
>
>
> But I get this error:
>
> TASK [Create the Jinja2 based template]
> *
> fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError:
> template error while templating string: expected token ':', got '}'.
> String: {% for layer in layers %}\n
>
>
>
>
> On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote:
>>
>> On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
>> Shifa Shaikh  wrote:
>>
>> > How do i  put the if /else condition in the jinja template ?
>>
>> See "if"
>> https://jinja.palletsprojects.com/en/2.11.x/templates/#if
>>
>
>> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> 
> .
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org
> 
> .
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAJtox0%3D1A%3DFE%3DbDc2Rpdf8bSevF8d3hOWBkebCmNfWx8EzV1Og%40mail.gmail.com.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
If I remove the of statement the error goes away.

I can confirm i'm using the same Jinja template as the output error shared.

On Fri, 6 Mar, 2020, 4:33 pm Jean-Yves LENHOF, 
wrote:

> Hi,
>
> Your error is about a for loop, but your template included in your email
> doesn't have this loop.
>
> Looks like you didn't give us the good one
>
> Regards,
>
> JYL
>
>
> Le 06/03/2020 à 11:52, Shifa Shaikh a écrit :
>
> Vladimir Hi,
>
> I tried
>
> {% if {{ playbook_dir }}/{{ item }}/bad*.txt | exists %}
>
>
> {{ item }}
>
>
>
> {% else %}
>
>
> {{ item }}
>
>
>
> {% endif %}
>
>
> But I get this error:
>
> TASK [Create the Jinja2 based template]
> *
> fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError:
> template error while templating string: expected token ':', got '}'.
> String: {% for layer in layers %}\n
>
>
>
>
> On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote:
>>
>> On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
>> Shifa Shaikh  wrote:
>>
>> > How do i  put the if /else condition in the jinja template ?
>>
>> See "if"
>> https://jinja.palletsprojects.com/en/2.11.x/templates/#if
>>
>
>> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> 
> .
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org
> 
> .
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAJtox0mLEi3K%3DA%3DP6J8B8EUnm8iz%2B%3DPYUBkJ-5R5tJF%2ByNheeg%40mail.gmail.com.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Jean-Yves LENHOF

Hi,

Your error is about a for loop, but your template included in your email 
doesn't have this loop.


Looks like you didn't give us the good one

Regards,

JYL


Le 06/03/2020 à 11:52, Shifa Shaikh a écrit :

Vladimir Hi,

I tried

|
{%if{{playbook_dir }}/{{item }}/bad*.txt |exists %}


{{item }}



{%else%}


{{item }}



{%endif %}

|

But I get this error:

|
TASK [Createthe Jinja2based 
template]*
fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: 
template error while templating string: expected token ':', got '}'. 
String: {% for layer in layers %}\n

|




On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote:

On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
Shifa Shaikh > wrote:

> How do i  put the if /else condition in the jinja template ?

See "if"
https://jinja.palletsprojects.com/en/2.11.x/templates/#if



--
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 ansible-project+unsubscr...@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com 
.


--
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
Vladimir Hi, 

I tried 

{% if {{ playbook_dir }}/{{ item }}/bad*.txt | exists %}


{{ item }}



{% else %}


{{ item }}



{% endif %}


But I get this error:

TASK [Create the Jinja2 based template] 
*
fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError: 
template error while templating string: expected token ':', got '}'. 
String: {% for layer in layers %}\n




On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote:
>
> On Fri, 6 Mar 2020 01:59:00 -0800 (PST) 
> Shifa Shaikh > wrote: 
>
> > How do i  put the if /else condition in the jinja template ? 
>
> See "if" 
> https://jinja.palletsprojects.com/en/2.11.x/templates/#if 
>

>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Vladimir Botka
On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
Shifa Shaikh  wrote:

> How do i  put the if /else condition in the jinja template ?

See "if" 
https://jinja.palletsprojects.com/en/2.11.x/templates/#if

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200306110546.1eaf83c6%40gmail.com.


pgp0yj5chXgX1.pgp
Description: OpenPGP digital signature


[ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
Here is my variable file

  layers:
- name: APP
  things:
- cactus
- lotus
- jasmine
- rose


- name: WAS
  things:
- mango
- apple



Below is my jinja template file:
{% for layer in layers %}


 
{% for item in layer.things %}

{{ item }}

{% endfor %}


{% endfor %}


My requirement is to put an if else condition where if any file err*txt is 
present under {{ item }} folder like below 

if `ls {{ playbook_dir }}/{{ item }}/err*.txt | head -1` returns true / 
records then the template evaluates to
{{ item }}
else
{{ item }}

How do i  put the if /else condition in the jinja template ?

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/09aeda5f-5e30-4b6c-b047-eda3c4c5de8b%40googlegroups.com.