I just started learning Ansible. It has been a pain so far. I have this code to create a new vm. I followed this tutorial.

- hosts: localhost
  connection: local
    - vsphere_guest:
            username: root
            password: pasword
            guest: newvm001
            state: powered_on
            validate_certs: no
                vcpu.hotadd: yes
                mem.hotadd:  yes
                notes: This is a test VM
                folder: MyFolder
                        size_gb: 10
                        type: thin
                        datastore: storage001
                    type: vmxnet3
                    network: VM Network
                    network_type: standard
                memory_mb: 256
                num_cpus: 1
                osid: ubuntu64Guest
                scsi: paravirtual

I however keep getting this error.

[WARNING]: Host file not found: /etc/ansible/hosts

[WARNING]: provided hosts list is empty, only localhost is available

PLAY [localhost]

TASK [setup] ******************************************************************* ok: [localhost]

TASK [vsphere_guest] *********************************************************** fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Cannot find datacenter named:"}

NO MORE HOSTS LEFT ************************************************************* [WARNING]: Could not create retry file 'testing.retry'. [Errno 2] No such file or directory: ''

PLAY RECAP ********************************************************************* localhost : ok=1 changed=0 unreachable=0 failed=1

Why is that so? What is a datacenter? How can i find the appropriate datacenter to use? And what is the difference between a host file and an inventory file?


You have one major problem and one minor problem.

First, the major problem: You haven't supplied the correct datacenter name.


This is supposed to be set to the name of the Datacenter object in vSphere. (And, as specified in the Ansible documentation, it should be set to ha-datacenter if you're talking to a standalone ESXi host.)

The minor problem is that you've used IP addresses rather than hostnames for connection information. What to do about this is obvious.

  • Wow. Thanks a million. We don't have a datacenter for the host so i was supposed to use ha-datacenter. And i fixed the ip address problem too – user3796292 Sep 1 '16 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.