Setting custom advanced configuration parameters in VMware VM when deploying via Ansible

587 views
Skip to first unread message

James

unread,
Jun 8, 2017, 6:03:16 PM6/8/17
to Ansible Project

I am trying to deploy a virtual machine via ansible and vcenter using the vmware_guest module and I need to pass additional custom parameters to the VM (vmx file).  I am using the custom values attribute to do this as it seems to be the correct way but I just cannot get it to work.  It always complains about the contents of the (first) key field and ignores all additional options.

 

The aim is to pass a number of items:

 

machine.id = "Something"

serial0.present = TRUE

etc

 

into the vmx file of the created VM (doing it manually via the file itself or using the vcenter GUI works fine of course).

 

This is what I have in ansible:

 

- hosts: guestnames

  gather_facts: no

  vars_files:

    - vars.yml

  tasks:

  - name: Create guests

    vmware_guest:

      hostname: "{{ vcenter_host }}"

      username: "{{ vcenter_username }}"

      password: "{{ vcenter_password }}"

      validate_certs: no

      esxi_hostname: "{{ esxi_ip }}"

      datacenter: datacenter

      name: "{{ inventory_hostname }}"

      guest_id: otherGuest64

      state: poweredoff

      template: my-template

      customvalues:

        - "key": "machine.id"

          "value": "test"

        - "key": "serial0.present"

          "value": "TRUE"

      disk:

      - size_gb: 5

        type: thin

        datastore: datastore1-{{hypervisorname}}

      hardware:

        memory_mb: 4096

        num_cpus: 4

    delegate_to: localhost

    register: deploy

  - debug:

      var: deploy

  - name: Show facts

    vmware_guest_facts:

      hostname: "{{ vcenter_host }}"

      username: "{{ vcenter_username }}"

      password: "{{ vcenter_password }}"

      datacenter: datacenter

      validate_certs: no

      name: "{{ inventory_hostname }}"

    delegate_to: localhost

    register: facts

  - debug:

      var: facts

 

 

And this is the output:

 

PLAYBOOK: start.yml ***************************************************************************************************************************************************************************************************

1 plays in start.yml

 

 

PLAY [guestnames] ************************************************************************************************************************************************************************************************************

META: ran handlers

 

 

TASK [Create guest] *****************************************************************************************************************************************************************************************************

fatal: [test16 -> localhost]: FAILED! => {

    "changed": false,

    "failed": true,

    "invocation": {

        "module_args": {

            "annotation": null,

            "cluster": null,

            "customization": {},

            "customvalues": [

                {

                    "key": "machine.id",

                    "value": "test"

                },

                {

                    "key": "serial0.present",

                    "value": "TRUE"

                }

            ],

            "datacenter": "datacenter",

            "disk": [

                {

                    "datastore": "datastore1-robbins",

                    "size_gb": 5,

                    "type": "thin"

                }

            ],

            "esxi_hostname": "10.10.10.10",

            "folder": "/vm",

            "force": false,

            "guest_id": "otherGuest64",

            "hardware": {

                "memory_mb": 4096,

                "num_cpus": 4

            },

            "hostname": "20.20.20.20",

            "is_template": false,

            "name": "test16",

            "name_match": "first",

            "networks": [],

            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",

            "resource_pool": null,

            "state": "poweredoff",

            "template": "my-template",

            "template_src": "my-template",

            "username": "admini...@vsphere.local",

            "uuid": null,

            "validate_certs": false,

            "wait_for_ip_address": false

        }

    },

    "msg": "Failed to set custom value for key='machine.id' and value='test'. Error was: (vmodl.fault.InvalidArgument) {\n   dynamicType = <unset>,\n   dynamicProperty = (vmodl.DynamicProperty) [],\n   msg = 'A specified parameter was not correct: key',\n   faultCause = <unset>,\n   faultMessage = (vmodl.LocalizableMessage) [],\n   invalidProperty = u'key'\n}"

}

fatal: [test15 -> localhost]: FAILED! => {

    "changed": false,

    "failed": true,

    "invocation": {

        "module_args": {

            "annotation": null,

            "cluster": null,

            "customization": {},

            "customvalues": [

                {

                    "key": "machine.id",

                    "value": "test"

                },

                {

                    "key": "serial0.present",

                    "value": "TRUE"

                }

            ],

            "datacenter": "datacenter",

            "disk": [

                {

                    "datastore": "datastore1-robbins",

                    "size_gb": 5,

                    "type": "thin"

                }

            ],

            "esxi_hostname": "10.10.10.10",

            "folder": "/vm",

            "force": false,

            "guest_id": "otherGuest64",

            "hardware": {

                "memory_mb": 4096,

                "num_cpus": 4

            },

            "hostname": "20.20.20.20",

            "is_template": false,

            "name": "test15",

            "name_match": "first",

            "networks": [],

            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",

            "resource_pool": null,

            "state": "poweredoff",

            "template": "my-template",

            "template_src": "my-template",

            "username": "admini...@vsphere.local",

            "uuid": null,

            "validate_certs": false,

            "wait_for_ip_address": false

        }

    },

    "msg": "Failed to set custom value for key='machine.id' and value='test'. Error was: (vmodl.fault.InvalidArgument) {\n   dynamicType = <unset>,\n   dynamicProperty = (vmodl.DynamicProperty) [],\n   msg = 'A specified parameter was not correct: key',\n   faultCause = <unset>,\n   faultMessage = (vmodl.LocalizableMessage) [],\n   invalidProperty = u'key'\n}"

}

 

 

PLAY RECAP ************************************************************************************************************************************************************************************************************

test15                     : ok=0    changed=0    unreachable=0    failed=1

test16                     : ok=0    changed=0    unreachable=0    failed=1

 

 

Any ideas?


Jackson Pollock

unread,
Oct 23, 2017, 2:57:17 PM10/23/17
to Ansible Project
I have exactly the same problem, was there every a fix?

thanks!
Reply all
Reply to author
Forward
0 new messages