I am trying to via a survey in AAP for the enduser to put in say “dev app” for network variable. This translates to where network value gets put in 12.0.0.0/24 so it gets the next IP in that vlan and also populates the vm network variable to pull “12 Network” This works if just putting in the vlan and network but most of end-users won’t know which vlan they need.
---
- name: Provision VM on VMware
hosts: localhost
gather_facts: false
vars:
# Dictionary to map user-friendly names to actual network details
network_settings:
"dev app":
vlan: "12.0.0.0/24"
network_name: "12 Network"
"prod app":
vlan: "10.0.0.0/24"
network_name: "10 Network"
# Add more mappings as needed
tasks:
- name: Set network variables based on user input
set_fact:
network_vlan: "{{ network_settings[network_choice].vlan }}"
network_name: "{{ network_settings[network_choice].network_name }}"
- name: Create a VM on VMware ESXi
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ validate_certs | default('false') }}"
datacenter: "{{ datacenter_name }}"
folder: "{{ vm_folder }}"
name: "{{ vm_name }}"
state: poweredon
guest_id: "{{ guest_id }}"
disk:
- size_gb: "{{ vm_disk_size_gb }}"
type: thin
datastore: "{{ vm_datastore }}"
hardware:
memory_mb: "{{ vm_memory_mb }}"
num_cpus: "{{ vm_num_cpus }}"
networks:
- name: "{{ network_name }}"
ip: "{{ ip }}"
netmask: "{{ netmask }}"
gateway: "{{ gateway }}"
dns_servers: "{{ dns_servers }}"
wait_for_ip_address: true
delegate_to: localhost