deploy VM in ESXi using Ansible

292 views
Skip to first unread message

Orkhan Mammadov

unread,
Jul 3, 2021, 11:14:21 AM7/3/21
to Ansible Project
Hi guys,

Could you please help me with the guidance to create VM in ESXi using ansible playbook?
I tried to find proper one over forums, unfortunately could not find. 
Regards.

phil.gr...@gmail.com

unread,
Jul 3, 2021, 1:45:47 PM7/3/21
to Ansible Project
https://docs.ansible.com/ansible/latest/scenario_guides/vmware_scenarios/faq.html#can-i-deploy-a-virtual-machine-on-a-standalone-esxi-server
"Yes. vmware_guest can deploy a virtual machine with required settings on a standalone ESXi server. However, you must have a paid license to deploy virtual machines this way. If you are using the free version, the API is read-only."

Orkhan Mammadov

unread,
Jul 4, 2021, 11:46:34 AM7/4/21
to Ansible Project
Actually,

I am using ESXi evaluation mode (free). I created .yml file with the following entry:

---
- name: Create VM
  vmware_guest:
    hostname: esxilab
    username: root
    password: 123456
    validate_certs: no
    folder: /ha-datacenter/vm (I am not sure if it is correctly added)
    name: testvm
    state: poweredon
    guest_id: centos64Guest
    esxi_hostname: 192.168.1.101
    disk:
    - size_gb: 10
      type: thin
      datastore: datastore1
    hardware:
      memory_mb: 1024
      num_cpus: 2
      scsi: paravirtual
    cdrom:
      type: iso
      iso_path: datastore1/iso files/CentOS-8.1.1911-x86_64-boot.iso
    networks:
      - name: VM Network
        mac: 00:0c:29:c6:fe:93
        ip: 192.168.1.105
        netmask: 255.255.255.0
        device_type: vmnic0
    wait_for_ip_address: yes
  delegate_to: localhost
  register: deploy_vm

However, while running the file, I get the following error message:

ERROR! 'vmware_guest' is not a valid attribute for a Play

The error appears to be in '/home/ansible/projects/test/deploy_vm.yml': line 2,                                                                              column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Create VM
  ^ here

Jim Barlow

unread,
Jul 4, 2021, 11:49:11 AM7/4/21
to ansible...@googlegroups.com
You will want to use the vmware_guest module:

There are great examples at the bottom of this page.  The first listed example is what you will want to use.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/07ee6c1e-86e0-4d41-b524-32dd869605f5n%40googlegroups.com.

Jim Barlow

unread,
Jul 4, 2021, 11:51:04 AM7/4/21
to ansible...@googlegroups.com
Sorry, I was behind on the thread. Please disregard.

Orkhan Mammadov

unread,
Jul 4, 2021, 11:55:08 AM7/4/21
to Ansible Project
yes, I followed exactly as mentioned in the 1st option

Wei-Yen Tan

unread,
Jul 4, 2021, 5:11:37 PM7/4/21
to ansible...@googlegroups.com
Looks like your vm_guest formatting part is wrong

From: ansible...@googlegroups.com <ansible...@googlegroups.com> on behalf of Orkhan Mammadov <m7o...@gmail.com>
Sent: Monday, July 5, 2021 3:46:34 AM
To: Ansible Project <ansible...@googlegroups.com>
Subject: [ansible-project] Re: deploy VM in ESXi using Ansible
 
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages