MKPhil
(MKPhil)
August 9, 2019, 11:27am
1
According to https://docs.ansible.com/ansible/latest/modules/vmware_guest_module.html I can rename a VM with Ansible by using:
name: Rename a virtual machine (requires the virtual machine’s uuid)
vmware_guest:
hostname: “{{ vcenter_hostname }}”
username: “{{ vcenter_username }}”
password: “{{ vcenter_password }}”
validate_certs: no
uuid: “{{ vm_uuid }}”
name: new_name
state: present
delegate_to: localhost
However, when I try this (Ansible 2.8.2) it complains about a missing folder and datacenter parameter. If those are supplied, the error then says
Unable to find the datastore with given parameters. This could mean, new_name is a non-existent virtual machine and module tried to deploy it as new virtual machine with no disk. Please specify disks parameter or specify template to clone from.
Any thoughts? Is the documentation wrong?
Akasurde
(Abhijeet Kasurde)
August 9, 2019, 11:49am
2
Are you sure the uuid
provided is correct uuid (hw_product_uuid in vmware guest facts) ?
I am able to rename existing VM using -
tasks:
- name: Gather facts about datastore
vmware_vm_facts:
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
validate_certs: no
folder: "{{ folder }}"
delegate_to: localhost
register: vm_facts
- set_fact:
vm_uuid: "{{ item.uuid }}"
with_items:
- "{{ vm_facts.virtual_machines | json_query(query) }}"
vars:
query: "[?guest_name=='test_00']"
- vmware_guest:
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
validate_certs: no
folder: "{{ folder }}"
uuid: "{{ vm_uuid }}"
name: "test_01"
state: present
Akasurde
(Abhijeet Kasurde)
August 9, 2019, 11:53am
3