# when conditional and IP address, is this a bug ?

**URL:** <https://forum.ansible.com/t/when-conditional-and-ip-address-is-this-a-bug/15223>\
**Category:** Ansible Project\
**Created:** [May 13, 2014, 4:17pm UTC](https://forum.ansible.com/t/when-conditional-and-ip-address-is-this-a-bug/15223 "2014-05-13T16:17:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julien\_Tognazzi](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Julien\_Tognazzi](https://forum.ansible.com/u/Julien_Tognazzi)\
**Post date:** [May 13, 2014, 4:17pm UTC](https://forum.ansible.com/t/when-conditional-and-ip-address-is-this-a-bug/15223/1 "2014-05-13T16:17:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 13, 2014, 4:45pm UTC](https://forum.ansible.com/t/when-conditional-and-ip-address-is-this-a-bug/15223/2 "2014-05-13T16:45:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 13, 2014, 7:48pm UTC](https://forum.ansible.com/t/when-conditional-and-ip-address-is-this-a-bug/15223/3 "2014-05-13T19:48:38Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![Julien\_Tognazzi](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Julien\_Tognazzi](https://forum.ansible.com/u/Julien_Tognazzi)\
**Post date:** [May 14, 2014, 6:55am UTC](https://forum.ansible.com/t/when-conditional-and-ip-address-is-this-a-bug/15223/4 "2014-05-14T06:55:13Z")

</div>

I really thought I tested your variant :-/

thanks anyway.
