title: when condition does not match with "ansible_host" Ansible 2.10?
body: <p>I try something very simple but it does not work:</p>
  <p>I want to execute a task only, if two strings are the same:</p>
  <p>hostname=1-Europe-ECV-Site2
  ansible_host=1-Europe-ECV-Site2</p>
  <p>This is the playbook:</p>
  <pre><code>- debug: var=hostname
  - debug: var=ansible_host
  
  - name: Gather a virtual machine info
    vmware_guest_info:
      hostname: '{{ vsphere_host }}'
      username: '{{ vsphere_user }}'
      password: '{{ vsphere_password }}'
      validate_certs: false
      datacenter: &quot;{{ vsphere_datacenter }}&quot;
      name: &quot;{{ hostname }}&quot;
      schema: vsphere
      properties:
        - guest.ipAddress
    retries: 60
    delay: 10
    until: gather_vm_info.instance.guest.ipAddress is not none
    register: gather_vm_info
    delegate_to: localhost
    when: ansible_host == hostname
  </code></pre>
  <p>I got this result, even if I can see by debugging, that both values are equal:</p>
  <pre><code>PLAY [Configure vyOS BGP LAN Router] *****************************************************************************************************************************************************
  
  TASK [get_ip_vsphere : debug] ************************************************************************************************************************************************************
  ok: [1-Europe-ECV-Site2] =&gt; 
    hostname: 1-Europe-ECV-Site2
  ok: [1-Europe-ECV-Site3] =&gt; 
    hostname: 1-Europe-ECV-Site3
  ok: [1-Europe-ECV-Site1-1] =&gt; 
    hostname: 1-Europe-ECV-Site1-1
  ok: [1-Europe-ECV-Site1-2] =&gt; 
    hostname: 1-Europe-ECV-Site1-2
  
  TASK [get_ip_vsphere : debug] ************************************************************************************************************************************************************
  ok: [1-Europe-ECV-Site2] =&gt; 
    ansible_host: 1-Europe-ECV-Site2
  ok: [1-Europe-ECV-Site3] =&gt; 
    ansible_host: 1-Europe-ECV-Site3
  ok: [1-Europe-ECV-Site1-1] =&gt; 
    ansible_host: 1-Europe-ECV-Site1-1
  ok: [1-Europe-ECV-Site1-2] =&gt; 
    ansible_host: 1-Europe-ECV-Site1-2
  
  TASK [get_ip_vsphere : Gather a virtual machine info] ************************************************************************************************************************************
  skipping: [1-Europe-ECV-Site2]
  skipping: [1-Europe-ECV-Site3]
  skipping: [1-Europe-ECV-Site1-1]
  skipping: [1-Europe-ECV-Site1-2]
  
  TASK [get_ip_vsphere : Gather a virtual machine info] ************************************************************************************************************************************
  skipping: [1-Europe-ECV-Site2]
  skipping: [1-Europe-ECV-Site3]
  skipping: [1-Europe-ECV-Site1-1]
  skipping: [1-Europe-ECV-Site1-2]
  </code></pre>
  <p>Question:
  Why this condition does not match? Do I need to do something special if I want to use the build in variable <strong>ansible_host</strong> I use Ansible 2.10</p>
  <p>EDIT:</p>
  <p>The purpose of this playbook is to write only the discovered IP address into the inventory YAML file under host_vars, if it is not already defined. As you can see in my example, the ansible_host is equal to the hostname of the VM, if no IP address was detected.</p>
  <p>For this I have to check if <strong>ansible_host == hostname</strong> and only then IP must be fetched and written into the YAML inventory file.</p>
  <p>Another solution is to check if 192.168. is not included in &quot;ansbile_host&quot; and then execute the task:</p>
  <pre><code>when: &quot;'192.168' in ansible_host&quot;
  </code></pre>
  <p>But this also does not work!</p>
  <p>What do I miss?</p>