Ansible and vmware_guest

Hi,

Forgive me for my bad english.

I’m actually experiencing some problems using the vmare_guest module. I want to create vms on vmware using this module.
When I create a new vm, the two nic cards are not connected at boot. This is the first problem.
The second one is that I can’t change the number of cores per vcpu and other specific configurations.

I tried to set custom values using customvalues:

customvalues:

  • key: “ethernet0.startConnected”
    value: true
  • key: “cpuid.coresPerSocket”
    value: 1

I have tested with ansible 2.3, 2.4 and 2.5 (from github). I can’t find any documentation to set customvalues.
How do you do this ? Thanks.

The totally code :

  • name: “Creating a VM based on template”
    vmware_guest:
    datacenter: “DC1”
    cluster: “mycluster”
    hostname: “{{ vcenter_host }}”
    username: “{{ vcenter_user }}”
    password: “{{ vcenter_password }}”
    validate_certs: no
    folder: {{ v_folder |default(“/”) }}
    name: “{{ v_hostname }}”
    annotation: “{{ ansible_date_time.date }} - VM creation {{ v_hostname }} using ansible”
    state: poweredon
    template: “{{ vmware_template }}”
    customvalues:
  • key: “vcpu.hotadd”
    values: “yes”
  • key: “mem.hotadd”
    value: “yes”
  • key: “ethernet0.startConnected”
    value: true
  • key: “cpuid.coresPerSocket”
    value: 1
    disk:
  • disk1:
    size_gb: 20
    type: “{{ v_disk_type }}”
    datastore: “mydatastore”
  • disk2:
    size_gb: “{{ v_disk_size }}”
    type: “{{ v_disk_type }}”
    datastore: “mydatastore”
    hardware:
    memory_mb: “{{ v_memory_size }}”
    num_cpus: “{{ v_cpu_number }}”
    scsi: paravirtual
    networks:
  • name: “{{ vmware_network }}”
    vlan: “{{ v_vlan_id }}”
    device_type: “e1000”
    type: “static”
    ip: “{{ v_ip }}”
    netmask: “{{ v_netmask | default(‘255.255.255.0’) }}”
    gateway: “{{ v_gateway }}”
    register: deploy
    when: do_action == “new”
    delegate_to: localhost
    tags: createvm

From what I have read, you need to specify a ‘name’ and ‘vlan’ parameter for each network interface you want configured in your clone, so maybe just add a

  • name: network2
    vlan: some_vlan_id

into to the ‘networks’ section?

You don’t mention what OS you are installing but something I have found while trying to clone windows VMs is that it is important to remove device drivers for any network devices which are no longer present (You can do this by starting Device Manager (devmgmt.msc) and clicking on ‘Show hidden devices’ on the View menu. I don’t know if the same is true for other operating systems.

I haven’t looked at the code, but I don’t think you can set the custom values that you are trying to set. Maybe you can set up templates with these values set and then just select the correct template. You can set number of cpus num_cpus and the memory allocation memory_mb in the ‘hardware’ section though (at least in ansible 2.4): http://docs.ansible.com/ansible/latest/vmware_guest_module.html

While I am on, I’ve also found that it is important to set the networking up in the same way in your template, at least on windows. So if you want to have static IPs in your cloned VMs make sure you have set up a static ip in your template VM before you convert it to a template.

Hope this helps,

Jon

Thanks. But I already have name and vlan in network section.

I’m not sure about my template. I’ll check the network configuration on it.

I’m trying to create Linux vms (centos).

reza.