# hostvars with variables for different hosts

**URL:** <https://forum.ansible.com/t/hostvars-with-variables-for-different-hosts/19413>\
**Category:** Ansible Project\
**Created:** [October 2, 2015, 9:08am UTC](https://forum.ansible.com/t/hostvars-with-variables-for-different-hosts/19413 "2015-10-02T09:08:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Belyakovsky](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Roman\_Belyakovsky](https://forum.ansible.com/u/Roman_Belyakovsky)\
**Post date:** [October 2, 2015, 9:08am UTC](https://forum.ansible.com/t/hostvars-with-variables-for-different-hosts/19413/1 "2015-10-02T09:08:56Z")

</div>

Hello!

Let’s say I have a simple dictionary in host\_vars or group\_vars:  
`host_presets: hostname: "{{ inventory_hostname.split('.')[0] }} domain: "{{ inventory_hostname| regex_replace('^' + inventory_hostname.split('.')[0] + '\\.', '')}}"`

It works perfectly till I try to get it for other host with hostvars[‘myvm’].host\_presets.hostname. In this case I get the hostname of the server that runs a playbook.

Is there a working way for dynamic predefining this kind of host/group vars?

Regards,  
Roman

---

<div class="post-metadata">

**Author:** ![Roman\_Belyakovsky](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Roman\_Belyakovsky](https://forum.ansible.com/u/Roman_Belyakovsky)\
**Post date:** [October 12, 2015, 6:19pm UTC](https://forum.ansible.com/t/hostvars-with-variables-for-different-hosts/19413/2 "2015-10-12T18:19:32Z")

</div>

FYI, opened an [issue](https://github.com/ansible/ansible/issues/12714).
