Run Ansible script on Server instead of directly in the host?

We have configured ansible with Foreman and we can run powershell scripts inside of the deployed hosts ok.

However in some cases we want to change settings for the VM that are not inside the VM, but in the hypervisor or elsewhere.
Would it be possible to run the ansible script inside the ansible server itself instead of the host directly?
if only the hostname would be known to the powershell script, I could query foreman API to gather all parameters myself (which vCenter it is running on, etc) and then run all tasks required.

Is this in any way possible?

thank you so much for this. I’m new to foreman and we’re still in POC/testing stage

Absolutely! We do this all the time from adding VM tags for every VM built to changing E1000 nics to VMXNET3, etc.

Check out the Ansible VMware collections.

You then run the role on the localhost

delegate_to: localhost

and use the magic vars with hostvars[inventory_hostname] for the VM you want to modify.

1 Like

ahhhh - let me tell the others. we’re going to try this out. sounds very promising. Thank you!!!