# Ansible\_host variable not working with community.vmware.vmware\_object\_role\_permisssion

**URL:** <https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923>\
**Category:** Get Help\
**Tags:** vmware, ansible-tower, playbook\
**Created:** [November 14, 2024, 9:54pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923 "2024-11-14T21:54:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jswope](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@jswope](https://forum.ansible.com/u/jswope)\
**Post date:** [November 14, 2024, 9:54pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/1 "2024-11-14T21:54:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![motorbass](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@motorbass](https://forum.ansible.com/u/motorbass)\
**Post date:** [November 15, 2024, 12:22pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/2 "2024-11-15T12:22:44Z")

</div>

[According to the documentation](https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_object_role_permission_module.html) they seems to use single quote , could you have a try like this (and define esxi\_hostname elsewhere, like a vars.yml file) :

```auto
- name: Assign user to VM folder
  community.vmware.vmware_object_role_permission:
    hostname: '{{ esxi_hostname }}'

```

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [November 15, 2024, 3:15pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/3 "2024-11-15T15:15:38Z")

</div>

> [@jswope](#):
>
> hostname: “{{ ansible\_host }}”

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?

> [@jswope](#):
>
> delegate\_to: redacted

What does this mean/do?

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [November 15, 2024, 3:25pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/4 "2024-11-15T15:25:46Z")

</div>

Try debugging the `ansible_host` variable?

```yaml
- 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?

---

<div class="post-metadata">

**Author:** ![jswope](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@jswope](https://forum.ansible.com/u/jswope)\
**Post date:** [November 15, 2024, 4:01pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/5 "2024-11-15T16:01:37Z")

</div>

Changing to single quotes does not resolve the issue.

---

<div class="post-metadata">

**Author:** ![jswope](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@jswope](https://forum.ansible.com/u/jswope)\
**Post date:** [November 15, 2024, 4:03pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/6 "2024-11-15T16:03:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jswope](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@jswope](https://forum.ansible.com/u/jswope)\
**Post date:** [November 15, 2024, 4:05pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/7 "2024-11-15T16:05:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [November 15, 2024, 4:27pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/8 "2024-11-15T16:27:56Z")

</div>

> [@jswope](#):
>
> delegate\_to: redacted

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

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [November 15, 2024, 4:29pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/9 "2024-11-15T16:29:14Z")

</div>

I took `redacted` to be a redacted domain name, eg `foo.example.org` 🤷 .

---

<div class="post-metadata">

**Author:** ![jswope](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@jswope](https://forum.ansible.com/u/jswope)\
**Post date:** [November 15, 2024, 4:53pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/11 "2024-11-15T16:53:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jswope](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@jswope](https://forum.ansible.com/u/jswope)\
**Post date:** [November 15, 2024, 5:07pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/12 "2024-11-15T17:07:29Z")

</div>

Still don’t know why ansible\_host doesn’t work but inventory\_hostname does. So I guess we can consider it resolved.

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [November 15, 2024, 5:16pm UTC](https://forum.ansible.com/t/ansible-host-variable-not-working-with-community-vmware-vmware-object-role-permisssion/10923/13 "2024-11-15T17:16:12Z")

</div>

> [@jswope](#):
>
> delegate\_to: tells where t run the operation.

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`?

```yaml
——
- hosts: ?

```
