when conditional and IP address, is this a bug ?

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.

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.

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

I really thought I tested your variant :-/

thanks anyway.