Trying to push a group role to esxi hosts. If I hard code the name of the host in the ansible tower template the job runs fine. However, if I use the ansible_host variable, the job fails with an Errno 111 Connection Refused.
This job template runs just fine if you replace ansible_host with a hard coded host name. I have put debug commands to display the value of ansible_host and it is the host name I am expecting. I have tried assigning that value to another variable and then using that variable for the value hostname. No luck.
According to the documentation they seems to use single quote , could you have a try like this (and define esxi_hostname elsewhere, like a vars.yml file) :
- name: Assign user to VM folder
community.vmware.vmware_object_role_permission:
hostname: '{{ esxi_hostname }}'
ansible_host is the playbook target host(s) from your inventory and maybe you have some variable for your esxi hosts set in your inventory that causes the error?
My guess would be that ansible_host is a IP address and the name you have been hardcoding is a domain name and SSH locally is configured differently for the IP address and the domain name?
Using debug message to print out the value of ansible_host shows exactly what I expect. The host name from the inventory that I am trying to run the playbook against.
I have been hardcoding the FQDN of the host when doing so. The inventory being used also has the FQDN of the host. The inventory host name is what is being passed as ansible_host variable.
delegate_to: tells where t run the operation. I am not running on the tower server (localhost) due to some strange security requirements. I am running on a different host and redacted the host name.
Yes. Which means that redacted should be a host or group from your inventory, but I do believe it should be set to localhost in this case.
When you «hard code» the hostnames, what is hosts set to in your playbook vs when you use ansible_host?