when condition

42 views
Skip to first unread message

Diogene Laerce

unread,
Jul 18, 2014, 12:33:05 PM7/18/14
to ansible...@googlegroups.com
Hi,

I would like to evaluate the following condition :

#############################################

- name: Make Debian package
shell: command=make deb chdir=/home/{{ user_installer }}/src/Python.3.4.1
when: "os.path.isdir('/home/{{ user_installer }}/src/Python-3.4.1') == True"

#############################################

But I get this error message :

"error when evaluating conditional"

The condition should return True. Do I do something syntactically wrong ?
I saw this syntax on Google but with previous versions of Ansible, does
it still
support this ?

Thanks,

--
“One original thought is worth a thousand mindless quotings.”
“Le vrai n'est pas plus sûr que le probable.”

Diogene Laerce



signature.asc

Michael DeHaan

unread,
Jul 18, 2014, 2:15:24 PM7/18/14
to ansible...@googlegroups.com
You don't use Jinja2 inside when statements.   Further, not all python functions, including the OS module, are exposed, and what you are saying would be an implicit local operation anyway.

You would need to run the stat module, register the result, and use that

- stat: path=/path/to/file
  register: foo

- deubg: var=foo  # see what's available in foo, just as an FYI

- shell: example
  when: foo.stat.isdir


Diogene Laerce

unread,
Jul 20, 2014, 6:39:48 AM7/20/14
to ansible...@googlegroups.com
Hi Michael,

Thanks ! And "second hit bird" : I know now what my Debian shell means
by : "cannot stat".. Re-thanks. ;)


On 07/18/2014 08:15 PM, Michael DeHaan wrote:
> You don't use Jinja2 inside when statements. Further, not all python
> functions, including the OS module, are exposed, and what you are saying
> would be an implicit local operation anyway.
>
> You would need to run the stat module, register the result, and use that
>
> - stat: path=/path/to/file
> register: foo
>
> - deubg: var=foo # see what's available in foo, just as an FYI
>
> - shell: example
> when: foo.stat.isdir
>
>
>
>
> On Fri, Jul 18, 2014 at 12:31 PM, 'Diogene Laerce' via Ansible Project
> <ansible...@googlegroups.com
> <mailto:ansible...@googlegroups.com>> wrote:
>
> Hi,
>
> I would like to evaluate the following condition :
>
> #############################################
>
> - name: Make Debian package
> shell: command=make deb chdir=/home/{{ user_installer
> }}/src/Python.3.4.1
> when: "os.path.isdir('/home/{{ user_installer }}/src/Python-3.4.1')
> == True"
>
> #############################################
>
> But I get this error message :
>
> "error when evaluating conditional"
>
> The condition should return True. Do I do something syntactically
> wrong ?
> I saw this syntax on Google but with previous versions of Ansible, does
> it still
> support this ?
>
> Thanks,
>
> --
> “One original thought is worth a thousand mindless quotings.”
> “Le vrai n'est pas plus sûr que le probable.”
>
> Diogene Laerce
>
>
>
>
> --
> 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-proje...@googlegroups.com
> <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com
> <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgyhaASa9cuccDpTnVpMWc1_653pgojeg%3Dhajf_AMxNNyQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgyhaASa9cuccDpTnVpMWc1_653pgojeg%3Dhajf_AMxNNyQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
signature.asc
Reply all
Reply to author
Forward
0 new messages