# Install Packages after VM is created in VSphere

**URL:** <https://forum.ansible.com/t/install-packages-after-vm-is-created-in-vsphere/36818>\
**Category:** Ansible Project\
**Tags:** azure, vmware\
**Created:** [July 8, 2022, 11:31am UTC](https://forum.ansible.com/t/install-packages-after-vm-is-created-in-vsphere/36818 "2022-07-08T11:31:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![harsh\_chawda](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@harsh\_chawda](https://forum.ansible.com/u/harsh_chawda)\
**Post date:** [July 8, 2022, 11:31am UTC](https://forum.ansible.com/t/install-packages-after-vm-is-created-in-vsphere/36818/1 "2022-07-08T11:31:23Z")

</div>

Hello All,

I am Creating VM in vCenter using **community.vmware.vmware\_guest,** after the VM is Created I have certain prerequisites to be fulfilled:

- Do Patching
- Do some package installation.
- And some more

How to accomplish this. I am able to create the VM then in the next task how to connect to VM and perform the above mentioned tasks.

Just In case in Terraform there is remote-exec and local-exec modules, after creation of VM in azure i can directly connect to VM using these and do whatever i need.

Can someone please provide the roadmap.

Thanks in advance,

**Regards**  
**Harsh**

---

<div class="post-metadata">

**Author:** ![abhijeetJanwalkar](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@abhijeetJanwalkar](https://forum.ansible.com/u/abhijeetJanwalkar)\
**Post date:** [July 10, 2022, 1:38pm UTC](https://forum.ansible.com/t/install-packages-after-vm-is-created-in-vsphere/36818/2 "2022-07-10T13:38:59Z")

</div>

Hi Harsh,

I just finished something like this.  
a Role with multiple tasks to install more 6 agents, make registry changes, add HDDs and format them, add more than one NIC and assign correct IP and a lot more…

I have another role to Patch the Template working on scheduling that Role/Playbook.

Warm Regards,  
Abhi

---

<div class="post-metadata">

**Author:** ![harsh\_chawda](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@harsh\_chawda](https://forum.ansible.com/u/harsh_chawda)\
**Post date:** [July 11, 2022, 4:01am UTC](https://forum.ansible.com/t/install-packages-after-vm-is-created-in-vsphere/36818/3 "2022-07-11T04:01:50Z")

</div>

Hello Abhijeet,

Thanks a lot for your information. Is there any way i can have a look on the roles you built or how you did it? It will be really helpful.  
As i am clueless on how to achieve this. I am okay till VM creation, but how to connect to the VM on the next task and do activities i am bit confused on that.

Thanks,

Regards  
Harsh

---

<div class="post-metadata">

**Author:** ![abhijeetJanwalkar](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@abhijeetJanwalkar](https://forum.ansible.com/u/abhijeetJanwalkar)\
**Post date:** [July 11, 2022, 8:35am UTC](https://forum.ansible.com/t/install-packages-after-vm-is-created-in-vsphere/36818/4 "2022-07-11T08:35:29Z")

</div>

Hi Harsha,  
I have used an input yaml file to give all the required variable values for the role to work.  
used this module community.vmware.vmware\_vm\_shell: extensively to avoid opening fw ports.  
As I am not connecting the VM over nw i dont need to add it in the inventory.  
All required installers are part of the Template but even if they are not you can use this module community.vmware.vsphere\_copy to copy files without nw.

I am doing this in vCenter so that was the difference against your use case for Azure.

---

<div class="post-metadata">

**Author:** ![daemenseth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/daemenseth/32/677_2.png) [@daemenseth](https://forum.ansible.com/u/daemenseth)\
**Post date:** [July 12, 2022, 6:19pm UTC](https://forum.ansible.com/t/install-packages-after-vm-is-created-in-vsphere/36818/5 "2022-07-12T18:19:29Z")

</div>

What I do is we create the vm. I use there a custom role for.  
Then we add that machine to the inventory. This action in in memory in a prestage group.  
The prestage group in the inventory has the credential and info to connect.  
And then we connect to that machine in the same playbook.

For a example see: [create vm](https://gist.github.com/daemenseth/8fe5c46957846d8aa4790ac698423c71)

---

<div class="post-metadata">

**Author:** ![harsh\_chawda](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@harsh\_chawda](https://forum.ansible.com/u/harsh_chawda)\
**Post date:** [July 13, 2022, 4:59am UTC](https://forum.ansible.com/t/install-packages-after-vm-is-created-in-vsphere/36818/6 "2022-07-13T04:59:13Z")

</div>

Hello Abhijeet,

Thanks for the reply, will try that.

Thanks again

---

<div class="post-metadata">

**Author:** ![harsh\_chawda](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@harsh\_chawda](https://forum.ansible.com/u/harsh_chawda)\
**Post date:** [July 13, 2022, 5:03am UTC](https://forum.ansible.com/t/install-packages-after-vm-is-created-in-vsphere/36818/7 "2022-07-13T05:03:21Z")

</div>

Hello Daeme,

Thats just great and what i needed. Just a small doubt, what if its a single click deployment process and i want everything to be done without manual intervention. Like create VM, Do patching and the install softwares.

But here you told **“Then we add that machine to the inventory”** is that step manual ? If yes how to make it automated.

Thanks a lot,

**Regards**  
**Harsh Chawda**

---

<div class="post-metadata">

**Author:** ![daemenseth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/daemenseth/32/677_2.png) [@daemenseth](https://forum.ansible.com/u/daemenseth)\
**Post date:** [July 15, 2022, 7:51pm UTC](https://forum.ansible.com/t/install-packages-after-vm-is-created-in-vsphere/36818/8 "2022-07-15T19:51:45Z")

</div>

Hello harsch,

that step is automatic zie line 14 in my example.

[Create a vm and do action on it (github.com)](https://gist.github.com/daemenseth/8fe5c46957846d8aa4790ac698423c71)

---

<div class="post-metadata">

**Author:** ![harsh\_chawda](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@harsh\_chawda](https://forum.ansible.com/u/harsh_chawda)\
**Post date:** [July 16, 2022, 3:58am UTC](https://forum.ansible.com/t/install-packages-after-vm-is-created-in-vsphere/36818/9 "2022-07-16T03:58:15Z")

</div>

Hello Daeme,

Thanks a lot for your help…😊💛

Regards  
Harsh Chawda
