Ansible_host variable not working with community.vmware.vmware_object_role_permisssion

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.

tasks:

  • name: Push role
    community.vmware.vmware_object_role_permission:
    hostname: “{{ ansible_host }}”
    username: “{{ansible_user }}”
    password: “{{ansible_password }}”
    role: ReadOnly
    group: “redacted”
    object_name: rootFolder
    validate_certs: false
    state: present
    delegate_to: redacted

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.

Any suggestions.

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?

What does this mean/do?

Try debugging the ansible_host variable?

- name: Debug ansible_host
  ansible.builtin.debug:
    var: ansible_host

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?

Changing to single quotes does not resolve the issue.

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.

I repeat, what does this do/mean?
Shouldn’t it be delegate_to: localhost?

I took redacted to be a redacted domain name, eg foo.example.org :person_shrugging: .

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.

1 Like

Still don’t know why ansible_host doesn’t work but inventory_hostname does. So I guess we can consider it resolved.

1 Like

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?

——
- hosts: ?