I was wondering if you figured out the "*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.*" part and update you with my findings as I ran into this as well.
It was as simple as adding perl to my base template as it is needed to do the customization after deployment. Cheers, Tipton On Wednesday, August 24, 2022 at 12:07:44 AM UTC-4 mgma...@gmail.com wrote: > I'll keep adding with my findings, might save people some time. > > Wrote playbook: > - hosts: localhost > gather_facts: false > vars_files: > - all_config.yml > > tasks: > - name: Gathering info from vms > community.vmware.vmware_vm_info: > > hostname: "{{ vcenter_hostname }}" > username: "{{ vcenter_username }}" > password: "{{ vcenter_password }}" > validate_certs: False > folder: "/Datacenter/vm/deployments/ubuntu" > delegate_to: localhost > register: vm_info > - debug: > var: name_ip > vars: > name_ip: "{{ vm_info.virtual_machines| > items2dict(key_name='guest_name', > value_name='ip_address') }}" > > which will spit out this: > > TASK [debug] > ************************************************************************************************************************************ > ok: [localhost] => { > "name_ip": { > "Ubuntu 22.04 VDI Template": "192.168.1.122", > "server01": "192.168.1.181", > "server02": "192.168.1.114", > "server03": "192.168.1.117" > } > } > > I think i'm getting close. Took me a whole 3 hours to figure this part. > > Now I need to save this into the ansible inventory (I think?) and run the > apt update and apt upgrade against those vms. > On Tuesday, August 23, 2022 at 7:15:20 PM UTC-4 TheReal MVP wrote: > >> I'm getting close :) >> >> I created this playbook after finding the vmware_vm_info module >> >> - hosts: all >> gather_facts: false >> become: false >> tasks: >> - name: Gathering info from vms from '{{ folder }}' >> community.vmware.vmware_vm_info: >> hostname: 192.168.1.51 >> username: admini...@vsphere.local >> password: password >> validate_certs: False >> folder: "/Datacenter/vm/deployments/ubuntu" >> delegate_to: localhost >> register: vm_info >> - debug: >> msg: "{{ vm_info }}" >> >> I'll get a dump of information from all 4 machines inside the folder >> specified. >> >> Now I need to find a way to extract the IP from it and save it somewhere >> to use it to connect to them :) >> >> >> On Tuesday, August 23, 2022 at 2:03:47 PM UTC-4 dhevanyo...@gmail.com >> wrote: >> >>> Just use terraform >>> >>> >>> On Tue., Aug. 23, 2022, 11:08 a.m. TheReal MVP, <mgma...@gmail.com> >>> wrote: >>> >>>> 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: 'admini...@vsphere.local' >>>> 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 ansible-proje...@googlegroups.com. >>>> >>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/ansible-project/86dd5fce-2f71-492c-bf20-73c8a74d8913n%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/ansible-project/86dd5fce-2f71-492c-bf20-73c8a74d8913n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- 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-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0b6a0e79-31e7-4b97-b115-96bfc90756d5n%40googlegroups.com.