# Can anyone tell me what is hostvars\[host\]|confluent.platform.resolve\_hostname in variable

**URL:** <https://forum.ansible.com/t/can-anyone-tell-me-what-is-hostvars-host-confluent-platform-resolve-hostname-in-variable/10346>\
**Category:** Get Help\
**Created:** [October 17, 2024, 7:09am UTC](https://forum.ansible.com/t/can-anyone-tell-me-what-is-hostvars-host-confluent-platform-resolve-hostname-in-variable/10346 "2024-10-17T07:09:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [October 17, 2024, 7:09am UTC](https://forum.ansible.com/t/can-anyone-tell-me-what-is-hostvars-host-confluent-platform-resolve-hostname-in-variable/10346/1 "2024-10-17T07:09:37Z")

</div>

zookeeper\_servers: “{% for host in groups[‘zookeeper’] %}{% if loop.index \> 1%},{% endif %}server.{{ hostvars[host][‘zookeeper\_id’] | default(groups.zookeeper.index(host) + 1)}}={{ zookeeper\_current\_node\_hostname if host == inventory\_hostname else hostvars[host]|confluent.platform.resolve\_hostname }}:{{zookeeper\_peer\_port}}:{{zookeeper\_leader\_port}}{% endfor %}”

---

<div class="post-metadata">

**Author:** ![mikemorency](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mikemorency/32/2672_2.png) [@mikemorency](https://forum.ansible.com/u/mikemorency)\
**Post date:** [October 17, 2024, 1:00pm UTC](https://forum.ansible.com/t/can-anyone-tell-me-what-is-hostvars-host-confluent-platform-resolve-hostname-in-variable/10346/2 "2024-10-17T13:00:40Z")

</div>

> Goes through selected possible VARs to provide the HOSTNAME for a given node for internal addressing within Confluent Platform

Taken from

> <https://github.com/confluentinc/cp-ansible/blob/master/plugins/filter/filters.py#L93-L98>

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [October 18, 2024, 1:52pm UTC](https://forum.ansible.com/t/can-anyone-tell-me-what-is-hostvars-host-confluent-platform-resolve-hostname-in-variable/10346/3 "2024-10-18T13:52:41Z")

</div>

Thanks Mike. However, i dont want to use it as confluent.platform.resolve\_hostname. We are customising as per our requirement so how do we restrain from using confluent.platform.resolve\_hostname cant we directly use “|resolve\_hostname” or similar to it . I wanted to avoid using collection and use it as a role.

---

<div class="post-metadata">

**Author:** ![mikemorency](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mikemorency/32/2672_2.png) [@mikemorency](https://forum.ansible.com/u/mikemorency)\
**Post date:** [October 18, 2024, 2:39pm UTC](https://forum.ansible.com/t/can-anyone-tell-me-what-is-hostvars-host-confluent-platform-resolve-hostname-in-variable/10346/4 "2024-10-18T14:39:34Z")

</div>

> I wanted to avoid using collection and use it as a role.

Im not sure what you mean by this. Could you elaborate?

If you just dont want to use this specific collection, you could either maintain a copy of the plugin yourself, or write the logic in jinja/ansible. Maybe like

```auto
..... if host == inventory_hostname else (
  hostvars[host]['hostname_aliasing_enabled'] | ternary(
    (
      hostvars[host]['hostname'] | default(
        hostvars[host]['ansible_host'] | default(
          hostvars[host]['inventory_hostname']
        )
      )
    ),
    (
      hostvars[host]['inventory_hostname']
    )
  )
)

```

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [October 18, 2024, 2:56pm UTC](https://forum.ansible.com/t/can-anyone-tell-me-what-is-hostvars-host-confluent-platform-resolve-hostname-in-variable/10346/5 "2024-10-18T14:56:56Z")

</div>

Yes i want to maintain the local copy of plugin.  
Now what happens is because the variable is used like "confluent.platform.resolve\_hostname " its obliged to have ansible colletion FCQN like ansible/collections/ansible\_collections/confluent/platform/ . I dont want this to have it on control machine. Is it not possible to use simply hostvars[host]|resolve\_hostname instead hostvars[host]|confluent.platform.resolve\_hostname. If i can use like this i dont need to have ansible collection directory structure to maintain. I can simply use it as a role.

---

<div class="post-metadata">

**Author:** ![mikemorency](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mikemorency/32/2672_2.png) [@mikemorency](https://forum.ansible.com/u/mikemorency)\
**Post date:** [October 18, 2024, 3:19pm UTC](https://forum.ansible.com/t/can-anyone-tell-me-what-is-hostvars-host-confluent-platform-resolve-hostname-in-variable/10346/6 "2024-10-18T15:19:27Z")

</div>

> Yes i want to maintain the local copy of plugin.

You can place the copy of the plugin locally as described here: [Filter plugins — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/plugins/filter.html#using-filter-plugins)

Or you can adjust your variable like this. Im not confident this works, but I think you can take it from here

```auto
zookeeper_servers: “{% for host in groups[‘zookeeper’] %}{% if loop.index > 1%},{% endif %}server.{{ hostvars[host][‘zookeeper_id’] | default(groups.zookeeper.index(host) + 1)}}={{ zookeeper_current_node_hostname if host == inventory_hostname else (hostvars[host]['hostname_aliasing_enabled'] | ternary((hostvars[host]'hostname'] | default(hostvars[host]['ansible_host'] | default(hostvars[host]['inventory_hostname']))), (hostvars[host]['inventory_hostname']))) }}:{{zookeeper_peer_port}}:{{zookeeper_leader_port}}{% endfor %}”

```

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [October 18, 2024, 3:27pm UTC](https://forum.ansible.com/t/can-anyone-tell-me-what-is-hostvars-host-confluent-platform-resolve-hostname-in-variable/10346/7 "2024-10-18T15:27:02Z")

</div>

Sure. Thanks for your reply mike. I will try and let u know

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 17, 2024, 3:27pm UTC](https://forum.ansible.com/t/can-anyone-tell-me-what-is-hostvars-host-confluent-platform-resolve-hostname-in-variable/10346/8 "2024-11-17T15:27:49Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
