when conditional and IP address, is this a bug ?

165 views
Skip to first unread message

Julien Tognazzi

unread,
May 13, 2014, 12:17:21 PM5/13/14
to ansible...@googlegroups.com
Hello,

Running this test playbook, I have the following error:

- hosts: localhost

  tasks:
  - name: Test IP address
    debug: msg="ok"
    when: "{{ ansible_lo.ipv4.address }} == 127.0.0.1"

 [WARNING]: It is unneccessary to use '{{' in conditionals, leave variables in
loop expressions bare.

PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [Test IP address] *******************************************************
fatal: [localhost] => error while evaluating conditional: 127.0.0.1 == 127.0.0.1

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/home/admin/test.retry

localhost                  : ok=1    changed=0    unreachable=1    failed=0


I also tested without the quotes, and got the same error ?

I eventually change the test to be
      when: ansible_lo.ipv4.address.find('127.0.0.1') != -1

But I don't understand why the first one always give an error.

Any explanation ?
Is is a bug ?

My ansible version is 1.5.5 on centos6

Thanks,

Julien.

Matt Martz

unread,
May 13, 2014, 12:45:14 PM5/13/14
to Julien Tognazzi, ansible...@googlegroups.com
You when line need to be manipulated just a bit to look like:

when: ansible_lo.ipv4.address == "127.0.0.1"

You don't need {{}} in a when statement, you don't need to quote the whole line and you need to individually quote the IP address.
-- 
Matt Martz
ma...@sivel.net
--
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.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/09552c1a-7c58-4049-ac68-e5934f75c520%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael DeHaan

unread,
May 13, 2014, 3:48:38 PM5/13/14
to ansible...@googlegroups.com, Julien Tognazzi
You're getting an error because both the left and right value need to be quoted due to the extra template evaluation you had requested, which is why Ansible is giving the warning about this.

This is simplified if you leave off the unneccessary {{ foo }} and just say "foo".


Julien Tognazzi

unread,
May 14, 2014, 2:55:13 AM5/14/14
to ansible...@googlegroups.com
I really thought I tested your variant :-/

thanks anyway.
Reply all
Reply to author
Forward
0 new messages