Create VMware vSphere VM with Ansible: Full Playbook Guide — Video Tutorial
Master creating VMware vSphere VMs using Ansible. Our guide provides a comprehensive playbook and step-by-step instructions for VM setup and management.
Watch Video
Watch "Create VMware vSphere VM with Ansible: Full Playbook Guide" on YouTube
What You'll Learn
- How to create a VMware vSphere Virtual Machine with Ansible?
- Ansible creates a VMware vSphere Virtual Machine
- Parameters
- Links
- code
- execution
- after execution
- Conclusion
- Related Articles
Full Tutorial Content
How to create a VMware vSphere Virtual Machine with Ansible?
I'm going to show you a live Playbook and some simple Ansible code.
I'm Luca Berton and welcome to today's episode of Ansible Pilot
Ansible creates a VMware vSphere Virtual Machine
> `community.vmware.vmware_guest` Manages virtual machines in vCenter
Today we're talking about the Ansible module `vmware_guest`.
The full name is `community.vmware.vmware_guest`, which means that is part of the collection of modules to interact with VMware, community-supported.
It's a module pretty stable and out for years.
It manages virtual machines in vCenter.
Parameters
The module `vmware_guest` has a very long list of parameters to customize all your needs to create a VMware vSphere Virtual Machine. Please refer to manual for the full list.
Links
- [community.vmware.vmware_guest](https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_guest_module.html)
## Playbook
How to create a VMware vSphere Virtual Machine with Ansible.
I'm going to show you how to create a Virtual Machine named "myvm" with the following resources:
- 1 CPU
- 1 GB of RAM
- 10 GB of storage, thin-provisioned in the datastore "Datastore-1"
network card name "VM Network", type "vmxnet3"
code
- create_vm.yml
```yaml
---
- name: create vm Playbook
hosts: localhost
become: false
gather_facts: false
collections:
- community.vmware
pre_tasks:
- include_vars: vars.yml
tasks:
- name: create folder
vcenter_folder:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ vcenter_validate_certs }}"
datacenter_name: "{{ vcenter_datacenter }}"
folder_name: "{{ vcenter_destination_folder }}"
folder_type: vm
state: present
- name: create VM
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ vcenter_validate_certs }}"
datacenter: "{{ vcenter_datacenter }}"
name: "{{ vm_name }}"
folder: "{{ vcenter_destination_folder }}"
state: "{{ vm_state }}"
guest_id: "{{ vm_guestid }}"
cluster: "{{ vcenter_cluster }}"
disk:
- size_gb: "{{ vm_disk_gb }}"
type: "{{ vm_disk_type }}"
datastore: "{{ vm_disk_datastore }}"
hardware:
memory_mb: "{{ vm_hw_ram_mb }}"
num_cpus: "{{ vm_hw_cpu_n }}"
scsi: "{{ vm_hw_scsi }}"
networks:
- name: "{{ vm_net_name }}"
device_name: "{{ vm_net_type }}"
```
- vars.yml
```yaml
---
vcenter_hostname: "vmware.example.com"
vcenter_datacenter: "vmwaredatacenter"
vcenter_validate_certs: false
vcenter_username: "username@vsphere.local"
vcenter_password: "MySecretPassword123"
vm_name: "myvm"
vm_guesti
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 3 min
- Category: troubleshooting
Read the full written article: Create VMware vSphere VM with Ansible: Full Playbook Guide
Topics Covered
Related Video Tutorials
- How to Add a Disk to a VMware VM Using Ansible Playbook — Learn how to add a disk to a VMware VM using an Ansible playbook. This guide includes the YAML configuration, variables, and execution steps for easy automation.
- Configure Ansible Dynamic Inventory for VMware in Simple Steps — Discover how to configure Ansible Dynamic Inventory for VMware to automate and manage virtual machines efficiently. Step-by-step guide with Playbook included.
- Configuring Ansible for VMware: Complete Setup Guide & Playbook — Learn how to set up Ansible for VMware with pyVmomi and the community.vmware collection. Follow our guide to configure and run your first VMware playbook.
- Configure a Python Virtual Environment for Ansible VMware - ansible collection community.vmware — Learn how to set up a Python Virtual Environment for Ansible VMware, ensuring seamless integration and management of your VMware infrastructure with Ansible community.vmware collection.
- Deploy a VMware vSphere Virtual Machine from a Template - Ansible module vmware_guest — How to automate the deployment of a virtual machine guest from “mytemplate” template using Ansible Playbook and vmware_guest module.
- Gather VMware ESX/ESXi Host Info with Ansible — Discover how to gather info about VMware ESX/ESXi hosts in a cluster using Ansible. Follow our live Playbook and simple code examples to get started.