Error trying to create a new vm in ansible

2019-09-11 12:43发布

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? And what is the difference between a host file and an inventory file?

1条回答
ゆ 、 Hurt°
2楼-- · 2019-09-11 13:17

what is the difference between a host file and an inventory file?

They are the same. However, since you're doing everything on your local machine, it's fine that you only have localhost available.

This is your error:

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

It's not clear to me why you're receiving this with the playbook you've provided, as it doesn't mention that IP at all and the line I suspect is causing the problem is

datacenter: 1.1.1.12

Are you sure this is the file you're running, and that you've saved any changes you've made to it?

查看更多
登录 后发表回答