vsphere_guest module doesn't receve datastore value

34 views
Skip to first unread message

Arkanon

unread,
Jan 17, 2018, 2:04:53 PM1/17/18
to Ansible Project
Hello.

I want to deploy a VMWare Linux VM from a template and then customize IP and hostname.

With vmware_guest module the deploy where finished, but I couldn't set IP/hostname. So I changed to vsphere_guest module to give a try.
However, with vsphere module the deploy process doesn't even finish. The message received is:

"Could not clone selected machine: [Task Error]: Insufficient disk space on datastore ''."

Apparently datastore has no value, but it was set, accordingly with documentation in <http://docs.ansible.com/ansible/latest/vsphere_guest_module.html#examples>

Details:

$ ansible-playbook --version
ansible-playbook 2.5.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'HOME/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.14+ (default, Dec  5 2017, 15:17:02) [GCC 7.2.1 20171205]

$ cat vmware.yml
---

- name: interaction with vCenter
  hosts: localhost
  connection: local
  gather_facts: no

  vars:
    run_time: "{{ lookup('pipe','date \"+%Y/%m/%d %H:%M:%S\"') }}"
    domain: DOMAIN
    vc_hn: vcenter
    vc_un: "{{ lookup('env','USER') }}"
    vc_pw: "{{ lookup('env','password') }}"
    vc_dc: DC
    vc_cluster: CLUSTER
    vc_hv: 172.23.1.156
    vc_ds: Server1156
    vc_folder: FOLDER
    vm_name: test
    vm_note: Deployed with ansible
    vm_hn: test

  tasks:

    - name: Deploy VM from Template
      vsphere_guest:

        validate_certs: no
        vcenter_hostname: "{{ vc_hn }}.{{ domain }}"
        username: "{{ vc_un }}@{{ domain }}"
        password: "{{ vc_pw }}"
        guest: "{{ vm_name }}"
        from_template: yes
        template_src: CentOS-Template-7.3

        esxi:
          datacenter: "{{ vc_dc }}"
          hostname: "{{ vc_hv }}"

        vm_extra_config:
          notes: "{{ vm_note }} - {{ run_time }}"
          folder: "{{ vc_folder }}"

        vm_hardware:
          osid: centos64guest
          memory_mb: 2048
          num_cpus: 1
          scsi: paravirtual

        vm_disk:
          disk1:
            size_gb: 20
            type: thin
            datastore: "{{ vc_ds }}"

        vm_nic:
          nic1:
            type: vmxnet3
            network: VLAN_30
            network_type: dvs

$ ansible-playbook vmware.yml -vvv
ansible-playbook 2.5.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'HOME/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.14+ (default, Dec  5 2017, 15:17:02) [GCC 7.2.1 20171205]
Using /etc/ansible/ansible.cfg as config file
Parsed /etc/ansible/hosts inventory source with ini plugin

PLAYBOOK: vmware.yml **********************************************************************************************************
1 plays in vmware.yml

PLAY [interaction with vCenter] ***********************************************************************************************
META: ran handlers

TASK [Deploy VM from Template] ************************************************************************************************
task path: /export/fs/share/ansible/vmware.yml:28
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/cloud/vmware/vsphere_guest.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: USER
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo HOME/.ansible/tmp/ansible-local-5106E7cSQy/ansible-tmp-1516215130.16-200469515246412 `" && echo ansible-tmp-1516215130.16-200469515246412="` echo HOME/.ansible/tmp/ansible-local-5106E7cSQy/ansible-tmp-1516215130.16-200469515246412 `" ) && sleep 0'
<127.0.0.1> PUT HOME/.ansible/tmp/ansible-local-5106E7cSQy/tmpgXBBnA TO HOME/.ansible/tmp/ansible-local-5106E7cSQy/ansible-tmp-1516215130.16-200469515246412/vsphere_guest.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x HOME/.ansible/tmp/ansible-local-5106E7cSQy/ansible-tmp-1516215130.16-200469515246412/ HOME/.ansible/tmp/ansible-local-5106E7cSQy/ansible-tmp-1516215130.16-200469515246412/vsphere_guest.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python HOME/.ansible/tmp/ansible-local-5106E7cSQy/ansible-tmp-1516215130.16-200469515246412/vsphere_guest.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r HOME/.ansible/tmp/ansible-local-5106E7cSQy/ansible-tmp-1516215130.16-200469515246412/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_i9xfFO/ansible_module_vsphere_guest.py", line 754, in deploy_template
    vmTemplate.clone(guest, **cloneArgs)
  File "/usr/local/lib/python2.7/dist-packages/pysphere/vi_virtual_machine.py", line 535, in clone
    FaultTypes.TASK_ERROR)

fatal: [localhost]: FAILED! => {
    "attempts": 1,
    "changed": false,
    "invocation": {
        "module_args": {
            "cluster": null,
            "esxi": {
                "datacenter": "DC",
                "hostname": "172.23.1.156"
            },
            "force": false,
            "from_template": true,
            "guest": "teste",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "power_on_after_clone": true,
            "resource_pool": null,
            "snapshot_to_clone": null,
            "state": "present",
            "template_src": "CentOS-Template-7.3",
            "username": "USER",
            "validate_certs": false,
            "vcenter_hostname": "vcenter",
            "vm_disk": {
                "disk1": {
                    "datastore": "Server1156",
                    "size_gb": 20,
                    "type": "thin"
                }
            },
            "vm_extra_config": {
                "folder": "FOLDER",
                "notes": "Deployed with ansible - 2018/01/17 16:52:10"
            },
            "vm_hardware": {
                "memory_mb": 2048,
                "num_cpus": 1,
                "osid": "centos64guest",
                "scsi": "paravirtual"
            },
            "vm_hw_version": null,
            "vm_nic": {
                "nic1": {
                    "network": "VLAN_30",
                    "network_type": "dvs",
                    "type": "vmxnet3"
                }
            },
            "vmware_guest_facts": null
        }
    },
    "msg": "Could not clone selected machine: [Task Error]: Insufficient disk space on datastore ''."
}
        to retry, use: --limit @/export/fs/share/ansible/vmware.retry

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

What could I be doing wrong?

Thanks in advance.



Sebastien Desbois

unread,
Jan 22, 2018, 8:59:47 AM1/22/18
to Ansible Project
Hello,

When deploying from a template, this parameter will no be used.
Your VM will be deployed in the same datastore as the template.
This deployment is just a clone that will take by default all the parameters CPU / RAM / Disks of the template.

For my part, since I like complicated things, after the deployement, Ansible is launching a powercli script that will place the VM in a datastore based on categories and available space.
(The whole VM, not just the disk, in order not to have the vmx and log files in a datastore and the disk in another datastore)

J Hawkesworth

unread,
Jan 23, 2018, 3:16:56 AM1/23/18
to Ansible Project
I use vmware_guest to clone vms and it works fine.  However I recall having problems with using VMXNET3 and wound up switching to e1000e.  I think this is because VMXNET3 depends on vmware tools and so isn't available during the early boot up process (I could be wrong about why, but I definitely could not get ip assigned when using VMXNET3) - things may be different for you - I most clone windows vms, but worth experimenting with available network adaptors.

Hope this helps,

Jon
Reply all
Reply to author
Forward
0 new messages