Hi,
I want to use ansible to provision my vm from template using the vmware_guest module but I get the following error on subject. Below is the snippet of the playbook and the output/error.
TIA,
Lupin
##### playbook content ###
# Create a new VM from a template using the new vmware_guest module
- name: vm_via_ansible
hosts: localhost
gather_facts: false
connection: local
vars:
vcenter_hostname: [xxxxxxxxxxxxx.com](http://xxxxxxxxxxxxx.com)
vcenter_user: xxxxxxxxxx
vcenter_pass: xxxxxxxxxxxxxx
esxhost: xxxxxxxxxx
datastore: 061DEV
network: win_dev_netmon
vmtemplate: vmtemplate
vm_memory: 8192
vm_name: testdb
notes: Created by Ansible
dumpfacts: False
tasks:
- name: check name var
debug: msg="{{ vm_name }}"
- name: create VM from template
vmware_guest:
name: "{{ vm_name }}"
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
esxi_hostname: "{{ esxhost }}"
state: present
folder: 'LINUX'
disk:
- size_gb: 60
type: thin
datastore: "{{ datastore }}"
nic:
- type: vmxnet3
network: "{{ network }}"
network_type: standard
hardware:
memory_mb: "{{ vm_memory | default(1024) }}"
num_cpus: 2
datacenter: DC_20
template: "{{ vmtemplate }}"
wait_for_ip_address: yes
register: esxi_vm_new
################ error/output ################
TASK [check name var] **********************************************************
ok: [localhost] => {
"msg": "testdb"
}
TASK [create VM from template] *************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'name'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_aFi0P0/ansible_module_vmware_guest.py\", line 959, in <module>\n main()\n File \"/tmp/ansible_aFi0P0/ansible_module_vmware_guest.py\", line 906, in main\n name_match=module.params['name_match'])\n File \"/tmp/ansible_aFi0P0/ansible_module_vmware_guest.py\", line 315, in getvm\n self.getfolders()\n File \"/tmp/ansible_aFi0P0/ansible_module_vmware_guest.py\", line 281, in getfolders\n self.folder_map = self._build_folder_map(self.folders)\n File \"/tmp/ansible_aFi0P0/ansible_module_vmware_guest.py\", line 261, in _build_folder_map\n vmap = self._build_folder_map(x, vmap=vmap, inpath=thispath)\n File \"/tmp/ansible_aFi0P0/ansible_module_vmware_guest.py\", line 264, in _build_folder_map\n if not [x.config.name](http://x.config.name) in vmap['names']:\nAttributeError: 'NoneType' object has no attribute 'name'\n", "module_stdout": "", "msg": "MODULE FAILURE"}
to retry, use: --limit @/root/ansible-scripts/it.retry
PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1