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
tasks:
- vsphere_guest:
vcenter_hostname:1.1.1.12
username: root
password: pasword
guest: newvm001
state: powered_on
validate_certs: no
vm_extra_config:
vcpu.hotadd: yes
mem.hotadd: yes
notes: This is a test VM
folder: MyFolder
vm_disk:
disk1:
size_gb: 10
type: thin
datastore: storage001
vm_nic:
nic1:
type: vmxnet3
network: VM Network
network_type: standard
vm_hardware:
memory_mb: 256
num_cpus: 1
osid: ubuntu64Guest
scsi: paravirtual
esxi:
datacenter: 1.1.1.12
hostname: 1.1.1.12
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: 9.1.142.86"}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?
Best Answer
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.