# Deploy VMware VM Template and run script locally on VM

**URL:** <https://forum.ansible.com/t/deploy-vmware-vm-template-and-run-script-locally-on-vm/36788>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [June 29, 2022, 7:13pm UTC](https://forum.ansible.com/t/deploy-vmware-vm-template-and-run-script-locally-on-vm/36788 "2022-06-29T19:13:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Watters](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@Brian\_Watters](https://forum.ansible.com/u/Brian_Watters)\
**Post date:** [June 29, 2022, 7:13pm UTC](https://forum.ansible.com/t/deploy-vmware-vm-template-and-run-script-locally-on-vm/36788/1 "2022-06-29T19:13:06Z")

</div>

I was able to deploy VMs from a template and they get renamed but the hostname doesn’t actually get updated. I am still trying to figure out how to do that but I have a bash script that I run on the VM, SUSE 15 Linux server, which joins to a domain and adds to SUSE Manager. For the life of me I cannot figure out what I need to add to my Ansible playbook so when these VMs get deployed from the template the hostname gets updated with what I configured and that script gets run with the appropriate switches.

Any guidance or help would be appreciated.

---

<div class="post-metadata">

**Author:** ![David\_Foley](https://avatars.discourse-cdn.com/v4/letter/d/9e8a1a/32.png) [@David\_Foley](https://forum.ansible.com/u/David_Foley)\
**Post date:** [June 29, 2022, 7:54pm UTC](https://forum.ansible.com/t/deploy-vmware-vm-template-and-run-script-locally-on-vm/36788/2 "2022-06-29T19:54:39Z")

</div>

Can you share the Ansible Script that you have, Are you using the customization parameter?

Also, have you tried using some sort of Pipeline where you can run a second Script using Ansible.builtin.hostname

---

<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:** [June 30, 2022, 7:53am UTC](https://forum.ansible.com/t/deploy-vmware-vm-template-and-run-script-locally-on-vm/36788/3 "2022-06-30T07:53:39Z")

</div>

i did something like that recently with Windows Server 2019.  
Used module community.vmware.vmware\_guest:  
and under  
customization:

hostname: ‘{{ vm.Name }}’

to run various commands and install agents i used  
community.vmware.vmware\_vm\_shell:

In my case the agents were already on the template.  
But there is another module which will help you copy files to VM without using network.  
Hope that helps.

Abhi
