title: The error was: error while evaluating conditional
body: <p>I try to use insert a unique number to each server I have by using Ansible.</p>
  
  <p>As below, I wish these is:</p>
  
  <p>"1" in 192.168.60.6's myid.txt</p>
  
  <p>"2" in 192.168.60.7's myid.txt</p>
  
  <pre><code>- hosts: all
    gather_facts:True
    vars:
      servers:
        host1:
          ip: 192.168.60.6
          num: 1
        host2:
          ip: 192.168.60.7
          num: 2
        host3:
          ip: 192.168.60.8
          num: 3
  
    tasks:
      -name: write a unique number in myid.txt 
       lineinfile:
         dest: "/home/user/myid.txt"
         line: "{{ item.value.num }}"
       when: "{{ item.value.ip }} == {{ ansible_all_ipv4_addresses[1] }}"
       `enter code here`with_dict: "{{ servers }}"
  </code></pre>
  
  <p>Unfortunately, I got this error:</p>
  
  <pre><code>TASK [write unique number in myid] 
  
  *********************************************
  fatal: [192.168.60.6]: FAILED! =&gt; {"failed": true, "msg": "The conditional check '{{item.value.ip}} == {{ ansible_all_ipv4_addresses[1] }}' failed.   
  The error was: error while evaluating conditional ({{item.value.ip}} == {{ ansible_all_ipv4_addresses[1] }}): float object has no element 60
  
  The error appears to have been in '/home/shihhao/Desktop/BlueTech/ansible/kafka_playbook.yml': line 101, column 7,   
  but may be elsewhere in the file depending on the exact syntax problem.
  
  The offending line appears to be:
      - name: write unique number in myid
        ^ here\n"}
  </code></pre>
  
  <p>It seems once I add this line I will get the error.</p>
  
  <pre><code> when: "{{item.value.ip}} == {{ ansible_all_ipv4_addresses[1] }}"
  </code></pre>
  
  <p>BTW: {{ ansible_all_ipv4_addresses[1] }} is 192.168.60.6</p>