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),
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
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:
@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
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
@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]
@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
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
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
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
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.
>
>
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
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]
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.
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 %}
{{
15 matches
Mail list logo