vmware_guest: How to create a VM with a NIC, without specifying a MAC address on creation

1,257 views
Skip to first unread message

Lemar

unread,
Apr 26, 2017, 9:09:55 AM4/26/17
to Ansible Project
Hi All!

I'm running Ansible v2.3, and want to know if it's possible to create virtual machines with NIC's, without specifying a MAC address.

While it's listed as optional in the docs (http://docs.ansible.com/ansible/vmware_guest_module.html), the playbook fails unless a mac entry is created.


Version Info:

ansible 2.3.0.0

  config file = /etc/ansible/ansible.cfg

  configured module search path = Default w/o overrides

  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

Example playbook:
---
- hosts: test-vms
  gather_facts
: false
  connection
: local
  vars_prompt
:
   
- name: "esxi_user"
      prompt
: "Enter ESXi username"
     
private: no
   
- name: "esxi_pass"
      prompt
: "Enter ESXi password"
     
private: yes
  vars
:
    datacenter
: 'ha-datacenter'
    notes
: 'Created by Ansible'
  tasks
:
   
- name: "Deploy VM"
      vmware_guest
:
        name
: "{{ inventory_hostname }}"
        validate_certs
: False
        hostname
: "{{ esxi_hostname }}"
        username
: "{{ esxi_user }}"
        password
: "{{ esxi_pass }}"
        state
: present
        guest_id
: "{{ osid }}"
        disk
:
       
- size_gb: "{{ disk_size }}"
          type
: thin
          datastore
: "{{ datastore }}"
        hardware
:
          memory_mb
: "{{ memory }}"
          num_cpus
: "{{ cpucount }}"
        networks
:
       
- name: VM Network
      delegate_to
: localhost

results:
fatal: [test-vm01 -> localhost]: FAILED! => {
   
"changed": true,
   
"failed": true,
   
"invocation": {
       
"module_args": {
           
"annotation": null,
           
"cluster": null,
           
"customization": {},
           
"customvalues": [],
           
"datacenter": "ha-datacenter",
           
"disk": [
               
{
                   
"datastore": "datastore1",
                   
"size_gb": 10,
                   
"type": "thin"
               
}
           
],
           
"esxi_hostname": null,
           
"folder": "/vm",
           
"force": false,
           
"guest_id": "centos64Guest",
           
"hardware": {
               
"memory_mb": 512,
               
"num_cpus": 1
           
},
           
"hostname": "1.1.1.1",
           
"is_template": false,
           
"name": "test-vm01",
           
"name_match": "first",
           
"networks": [
               
{
                   
"name": "VM Network"
               
}
           
],
           
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
           
"resource_pool": null,
           
"state": "present",
           
"template_src": null,
           
"username": "root",
           
"uuid": null,
           
"validate_certs": false,
           
"wait_for_ip_address": false
       
}
   
},
   
"msg": "Invalid configuration for device '2'."
}

I'm sure I'm missing something obvious, so any help is appreciated!



 

J Hawkesworth

unread,
Apr 26, 2017, 12:40:13 PM4/26/17
to Ansible Project
Bit of a wild guess this, but just wondering if the issue is indentation?

        disk:
       
- size_gb: "{{ disk_size }}"
          type
: thin
          datastore
: "{{ datastore }}"
        hardware
:
          memory_mb
: "{{ memory }}"
          num_cpus
: "{{ cpucount }}"
        networks
:
       
- name: VM Network


might need to be


        disk:
         
- size_gb: "{{ disk_size }}"
            type
: thin
            datastore
: "{{ datastore }}"
        hardware
:
          memory_mb
: "{{ memory }}"
          num_cpus
: "{{ cpucount }}"
        networks
:
         
- name: VM Network

Lemar

unread,
Apr 26, 2017, 3:54:09 PM4/26/17
to Ansible Project
No luck there - changing the indentation yields the same error.

Lemar

unread,
Apr 28, 2017, 8:56:02 PM4/28/17
to Ansible Project
Found the issue!

The create_nic function within the vmware_guest module sets the nic's address type as 'assigned', which requires you to supply a MAC address.
The problem is, it will do this whether you supply a MAC address or not.

I've submitted a patch to fix this: https://github.com/ansible/ansible/pull/24138
Reply all
Reply to author
Forward
0 new messages