<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
<li>Documentation Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">vmware_guest</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ansible 2.3.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Jun 17 2014, 18:11:42) [GCC 4.8.2 20140120 (Red Hat 4.8.2-16)]"><pre class="notranslate"><code class="notranslate">$ansible 2.3.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Jun 17 2014, 18:11:42) [GCC 4.8.2 20140120 (Red Hat 4.8.2-16)]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[defaults]
host_key_checking = false
callback_plugins = callback
inventory = ../inventory/infra
roles_path = ../roles
retry_files_enabled = False"><pre class="notranslate"><code class="notranslate">[defaults]
host_key_checking = false
callback_plugins = callback
inventory = ../inventory/infra
roles_path = ../roles
retry_files_enabled = False
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Linux mymachine 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux"><pre class="notranslate"><code class="notranslate">Linux mymachine 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
</code></pre></div>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">The VM is created every time I launch the playbook. So finally we have a duplication of the VM.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Fill the following task for a play as "connection:local" and play it to connect to a vCenter in 5.5.0</p>

<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
- name: Create VMs for templates
  vmware_guest:
     hostname: &quot;{{ vsphere_server }}&quot;           #vmware
     username: &quot;{{ user }}&quot;             #vmware
     password: &quot;{{password }}&quot;          #vmware
     validate_certs: no
     cluster: &quot;{{ machine.cluster }}&quot;
     datacenter: &quot;{{ machine.datacenter }}&quot;
     name: &quot;{{ machine.name }}&quot;            #seen in the vsphere hostname
     name_match: first                          # supposed to prevent duplicated vm
     template: &quot;{{ template_windows if machine.os == 'windows' else template_linux }}&quot;
     hardware:
       memory_mb: &quot;{{ machine.memory }}&quot;
       num_cpus: &quot;{{ machine.vcpu }}&quot;
     networks : &quot;{{machine.iplist}}&quot;       
     disk: &quot;{{machine.vdisks}}&quot;           
     state: poweredon"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">Create VMs for templates</span>
  <span class="pl-ent">vmware_guest</span>:
     <span class="pl-ent">hostname</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ vsphere_server }}<span class="pl-pds">"</span></span>           <span class="pl-c"><span class="pl-c">#</span>vmware</span>
     <span class="pl-ent">username</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ user }}<span class="pl-pds">"</span></span>             <span class="pl-c"><span class="pl-c">#</span>vmware</span>
     <span class="pl-ent">password</span>: <span class="pl-s"><span class="pl-pds">"</span>{{password }}<span class="pl-pds">"</span></span>          <span class="pl-c"><span class="pl-c">#</span>vmware</span>
     <span class="pl-ent">validate_certs</span>: <span class="pl-s">no</span>
     <span class="pl-ent">cluster</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ machine.cluster }}<span class="pl-pds">"</span></span>
     <span class="pl-ent">datacenter</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ machine.datacenter }}<span class="pl-pds">"</span></span>
     <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ machine.name }}<span class="pl-pds">"</span></span>            <span class="pl-c"><span class="pl-c">#</span>seen in the vsphere hostname</span>
     <span class="pl-ent">name_match</span>: <span class="pl-s">first                          </span><span class="pl-c"><span class="pl-c">#</span> supposed to prevent duplicated vm</span>
     <span class="pl-ent">template</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ template_windows if machine.os == 'windows' else template_linux }}<span class="pl-pds">"</span></span>
     <span class="pl-ent">hardware</span>:
       <span class="pl-ent">memory_mb</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ machine.memory }}<span class="pl-pds">"</span></span>
       <span class="pl-ent">num_cpus</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ machine.vcpu }}<span class="pl-pds">"</span></span>
     <span class="pl-ent">networks </span>: <span class="pl-s"><span class="pl-pds">"</span>{{machine.iplist}}<span class="pl-pds">"</span></span>       
     <span class="pl-ent">disk</span>: <span class="pl-s"><span class="pl-pds">"</span>{{machine.vdisks}}<span class="pl-pds">"</span></span>           
     <span class="pl-ent">state</span>: <span class="pl-s">poweredon</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">When you play it several times, a new VM is created each time instead of using the one previously created, finally you get a duplicated VM</p>
<h5 dir="auto">ACTUAL RESULTS</h5>


<p dir="auto">Duplicated VM</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK [generateMachine : Create VMs for templates] ***************************************************************************************************************
task path: /root/3-quickVm_management/roles/generateMachine/tasks/linux.yml:3
Using module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/vmware/vmware_guest.py
&lt;127.0.0.1&gt; ESTABLISH LOCAL CONNECTION FOR USER: root
&lt;127.0.0.1&gt; EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
&lt;127.0.0.1&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p &quot;` echo /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258 `&quot; &amp;&amp; echo ansible-tmp-1510160462.81-92627317344258=&quot;` echo /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258 `&quot; ) &amp;&amp; sleep 0'
&lt;127.0.0.1&gt; PUT /tmp/tmpgQsSZr TO /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258/vmware_guest.py
&lt;127.0.0.1&gt; EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258/ /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258/vmware_guest.py &amp;&amp; sleep 0'
&lt;127.0.0.1&gt; EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258/vmware_guest.py; rm -rf &quot;/root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258/&quot; &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'
changed: [127.0.0.1] =&gt; {
    &quot;changed&quot;: true,
    &quot;failed&quot;: false,
    &quot;instance&quot;: {
        &quot;annotation&quot;: &quot;&quot;,
        &quot;current_snapshot&quot;: null,
        &quot;customvalues&quot;: {},
        &quot;guest_tools_status&quot;: &quot;guestToolsNotRunning&quot;,
        &quot;guest_tools_version&quot;: &quot;10249&quot;,
        &quot;hw_eth0&quot;: {
            &quot;addresstype&quot;: &quot;assigned&quot;,
            &quot;ipaddresses&quot;: null,
            &quot;label&quot;: &quot;Network adaptor 1&quot;,
            &quot;macaddress&quot;: &quot;00:50:56:94:07:93&quot;,
            &quot;macaddress_dash&quot;: &quot;00-50-56-94-07-93&quot;,
            &quot;summary&quot;: &quot;DVSwitch : 91 3f 14 50 7d 79 85 56-59 4d 79 63 62 a3 3f 23&quot;
        },
        &quot;hw_guest_full_name&quot;: null,
        &quot;hw_guest_id&quot;: null,
        &quot;hw_interfaces&quot;: [
            &quot;eth0&quot;
        ],
        &quot;hw_memtotal_mb&quot;: 8192,
        &quot;hw_name&quot;: &quot;myVm&quot;,
        &quot;hw_power_status&quot;: &quot;poweredOn&quot;,
        &quot;hw_processor_count&quot;: 2,
        &quot;hw_product_uuid&quot;: &quot;4214102c-be1d-4d67-04ee-8b9d116343ef&quot;,
        &quot;ipv4&quot;: null,
        &quot;ipv6&quot;: null,
        &quot;module_hw&quot;: true,
        &quot;snapshots&quot;: []
    },
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;annotation&quot;: null,
            &quot;cluster&quot;: &quot;myCluster&quot;,
            &quot;customization&quot;: {},
            &quot;customvalues&quot;: [],
            &quot;datacenter&quot;: &quot;myDatacenter&quot;,
            &quot;disk&quot;: [
                {
                    &quot;datastore&quot;: &quot;MyDatastore&quot;,
                    &quot;size_gb&quot;: 40,
                    &quot;type&quot;: &quot;thin&quot;
                },
                {
                    &quot;datastore&quot;: &quot;MyDatastore&quot;,
                    &quot;size_gb&quot;: 10,
                    &quot;type&quot;: &quot;thin&quot;
                }
            ],
            &quot;esxi_hostname&quot;: null,
            &quot;folder&quot;: &quot;/vm&quot;,
            &quot;force&quot;: false,
            &quot;guest_id&quot;: null,
            &quot;hardware&quot;: {
                &quot;memory_mb&quot;: &quot;8192&quot;,
                &quot;num_cpus&quot;: &quot;2&quot;
            },
            &quot;hostname&quot;: &quot;192.168.204.40&quot;,
            &quot;is_template&quot;: false,
            &quot;name&quot;: &quot;myVm&quot;,
            &quot;name_match&quot;: &quot;first&quot;,
            &quot;networks&quot;: [
                {
                    &quot;gateway&quot;: &quot;192.168.204.1&quot;,
                    &quot;ip&quot;: &quot;192.168.204.148&quot;,
                    &quot;name&quot;: &quot;myNetwork&quot;,
                    &quot;netmask&quot;: &quot;255.255.255.0&quot;
                }
            ],
            &quot;password&quot;: &quot;VALUE_SPECIFIED_IN_NO_LOG_PARAMETER&quot;,
            &quot;resource_pool&quot;: null,
            &quot;state&quot;: &quot;poweredon&quot;,
            &quot;template&quot;: &quot;myTemplate&quot;,
            &quot;template_src&quot;: &quot;myTemplate&quot;,
            &quot;username&quot;: &quot;XXXXXXXXX&quot;,
            &quot;uuid&quot;: null,
            &quot;validate_certs&quot;: false,
            &quot;wait_for_ip_address&quot;: false
        }
    }
}
"><pre class="notranslate"><code class="notranslate">TASK [generateMachine : Create VMs for templates] ***************************************************************************************************************
task path: /root/3-quickVm_management/roles/generateMachine/tasks/linux.yml:3
Using module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/vmware/vmware_guest.py
&lt;127.0.0.1&gt; ESTABLISH LOCAL CONNECTION FOR USER: root
&lt;127.0.0.1&gt; EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
&lt;127.0.0.1&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258 `" &amp;&amp; echo ansible-tmp-1510160462.81-92627317344258="` echo /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258 `" ) &amp;&amp; sleep 0'
&lt;127.0.0.1&gt; PUT /tmp/tmpgQsSZr TO /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258/vmware_guest.py
&lt;127.0.0.1&gt; EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258/ /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258/vmware_guest.py &amp;&amp; sleep 0'
&lt;127.0.0.1&gt; EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258/vmware_guest.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1510160462.81-92627317344258/" &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'
changed: [127.0.0.1] =&gt; {
    "changed": true,
    "failed": false,
    "instance": {
        "annotation": "",
        "current_snapshot": null,
        "customvalues": {},
        "guest_tools_status": "guestToolsNotRunning",
        "guest_tools_version": "10249",
        "hw_eth0": {
            "addresstype": "assigned",
            "ipaddresses": null,
            "label": "Network adaptor 1",
            "macaddress": "00:50:56:94:07:93",
            "macaddress_dash": "00-50-56-94-07-93",
            "summary": "DVSwitch : 91 3f 14 50 7d 79 85 56-59 4d 79 63 62 a3 3f 23"
        },
        "hw_guest_full_name": null,
        "hw_guest_id": null,
        "hw_interfaces": [
            "eth0"
        ],
        "hw_memtotal_mb": 8192,
        "hw_name": "myVm",
        "hw_power_status": "poweredOn",
        "hw_processor_count": 2,
        "hw_product_uuid": "4214102c-be1d-4d67-04ee-8b9d116343ef",
        "ipv4": null,
        "ipv6": null,
        "module_hw": true,
        "snapshots": []
    },
    "invocation": {
        "module_args": {
            "annotation": null,
            "cluster": "myCluster",
            "customization": {},
            "customvalues": [],
            "datacenter": "myDatacenter",
            "disk": [
                {
                    "datastore": "MyDatastore",
                    "size_gb": 40,
                    "type": "thin"
                },
                {
                    "datastore": "MyDatastore",
                    "size_gb": 10,
                    "type": "thin"
                }
            ],
            "esxi_hostname": null,
            "folder": "/vm",
            "force": false,
            "guest_id": null,
            "hardware": {
                "memory_mb": "8192",
                "num_cpus": "2"
            },
            "hostname": "192.168.204.40",
            "is_template": false,
            "name": "myVm",
            "name_match": "first",
            "networks": [
                {
                    "gateway": "192.168.204.1",
                    "ip": "192.168.204.148",
                    "name": "myNetwork",
                    "netmask": "255.255.255.0"
                }
            ],
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "resource_pool": null,
            "state": "poweredon",
            "template": "myTemplate",
            "template_src": "myTemplate",
            "username": "XXXXXXXXX",
            "uuid": null,
            "validate_certs": false,
            "wait_for_ip_address": false
        }
    }
}

</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.1.1.0
  config file = 
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.1.1.0
  config file = 
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto"><strong>hosts file:</strong></p>
<p dir="auto">[localhost]<br>
127.0.0.1</p>
<p dir="auto">[localhost:vars]<br>
ansible_connection=local</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">UBUNTU 16.04 LTS</p>

<h5 dir="auto">SUMMARY</h5>

<p dir="auto">Running a playbook with inventory file which have group of 127.0.0.1 and also with localhost as a host cause the playbook to be executed as if we have 2 hosts, but the commands actually runs on the same host, and can be faulty depends on the tasks.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="command:

ansible-playbook -i inventory/hosts playbook.yml

playbook:

- hosts: localhost
  connection: local
  tasks:
    - foo"><pre class="notranslate"><code class="notranslate">command:

ansible-playbook -i inventory/hosts playbook.yml

playbook:

- hosts: localhost
  connection: local
  tasks:
    - foo
</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">==&gt; default: TASK [setup] *******************************************************************<br>
==&gt; default: ok: [127.0.0.1]<br>
==&gt; default:<br>
==&gt; default: TASK [foo] *****************************************************<br>
==&gt; default: ok: [127.0.0.1 -&gt; localhost]</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">==&gt; default: TASK [setup] *******************************************************************<br>
==&gt; default: ok: [127.0.0.1]<br>
==&gt; default: ok: [localhost]<br>
==&gt; default:<br>
==&gt; default: TASK [foo] *****************************************************<br>
==&gt; default: ok: [localhost -&gt; localhost]<br>
==&gt; default: ok: [127.0.0.1 -&gt; localhost]</p>
<p dir="auto">I could bypass this issue by changing my command to:<br>
<strong>ansible-playbook -i localhost, playbook.yml</strong></p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate">
</code></pre></div>