Hi there, I've been banging my head with this for some time now and I can't figure it out.
I'm using Ansible the vmware commnity plugins to deploy 4 VMs from a template and they all have DHCP running. Ultimately, I want to be able to grab the IPs from all 4 VMs, connect to them and run some commands (possibly update them and push my main ansible ssh key). *config.yml* vcenter_hostname: 'FQDN-of-my-vcenter' vcenter_username: '[email protected]' vcenter_password: 'MyPassword' vcenter_datastore: 'Storage' vcenter_datacenter: 'Datacenter' vcenter_folder: 'deployments/ubuntu' vcenter_datastore: 'Storage' guest_id: 'Ubuntu64' guest_network_1: 'VM Network' guest_network_2: 'Docker' guest_wait_for_ip_address: 'yes' guest_state: 'poweredon' # - Prepare VMs information machine_user: user machine_initial_user: root machine_initial_password: P@ssw0rdP@ssw0rd *ansible.cfg* # config file for ansible -- http://ansible.com/ # ============================================== # nearly all parameters can be overridden in ansible-playbook # or with command line flags. ansible will read ANSIBLE_CONFIG, # ansible.cfg in the current working directory, .ansible.cfg in # the home directory or /etc/ansible/ansible.cfg, whichever it # finds first [defaults] # some basic default values... library = ./library # additional paths to search for roles in, colon separated roles_path = ./roles [inventory] #Nothing in here My playbook *deploy-vm.yaml* root@user-ubuntu:/opt/ansible/multiple_vm# more deploy-vm.yaml --- - hosts: all gather_facts: false vars_files: - config.yml roles: - deploy-vm */roles/deploy-vm/tasks/main.yaml* --- # Deploy a VM from a template using Ansible 'vmware_guest' module - name: Deploying VMs community.vmware.vmware_guest: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' validate_certs: no datacenter: '{{ vcenter_datacenter }}' #cluster: '{{ vcenter_cluster }}' #resource_pool: '{{ vcenter_resource_pool }}' folder: '{{ vcenter_folder }}' name: '{{ inventory_hostname }}' state: poweredon guest_id: '{{ guest_id }}' annotation: "{{ guest_notes }}" #disk: #- size_gb: 50 # type: thin # datastore: '{{ vcenter_datastore }}' networks: - name: '{{ guest_network_1 }}' #ip: '{{ guest_custom_ip }}' #netmask: '{{ guest_netmask }}' #gateway: '{{ guest_gateway }}' type: dhcp connected: true start_connected: true - name: '{{ guest_network_2 }}' #ip: '{{ guest_custom_ip }}' #netmask: '{{ guest_netmask }}' #gateway: '{{ guest_gateway }}' type: dhcp connected: true start_connected: true #dns_servers: #- '{{ guest_dns_server }}' hardware: memory_mb: '{{ guest_memory }}' num_cpus: '{{ guest_vcpu }}' customization: dns_servers: - '{{ guest_dns_server }}' domain : '{{ guest_domain_name }}' hostname: '{{ inventory_hostname }}' template: '{{ guest_template }}' wait_for_ip_address: '{{ guest_wait_for_ip_address }}' state: '{{ guest_state }}' delegate_to: localhost I'll deploy all 4 VMs with this inventory file [machines] server01 guest_memory='4096' guest_vcpu='2' guest_template='Ubuntu 22.04 Template' guest_custom_ip='' guest_notes='server01' server02 guest_memory='4096' guest_vcpu='2' guest_template='Ubuntu 22.04 Template' guest_custom_ip='' guest_notes='server02' server03 guest_memory='4096' guest_vcpu='2' guest_template='Ubuntu 22.04 Template' guest_custom_ip='' guest_notes='server03' [vms] 'VDI Template' guest_memory='2048' guest_vcpu='4' guest_template='Ubuntu 22.04 Template' guest_notes='VDI Template' I'll deploy everything with this command: ansible-playbook -i vm-to-deploy deploy-vm.yaml All 4 VMs get deployed at the same time! AWESOME! I'll need to right-click on each VMs and set the network to "connected" since it doesn't do this automatically, i'll need to figure this out. Now, how do I gather the DHCP information, connect to them and update them? I was reading on using the vmware community dynamic inventory plugin but i'm getting weird errors which I don't really understand, so I can't really post them here. Any points? Sorry for the very long post. -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/86dd5fce-2f71-492c-bf20-73c8a74d8913n%40googlegroups.com.
