# Best practices for host aliases?

**URL:** <https://forum.ansible.com/t/best-practices-for-host-aliases/14487>\
**Category:** Ansible Project\
**Created:** [February 4, 2014, 3:05pm UTC](https://forum.ansible.com/t/best-practices-for-host-aliases/14487 "2014-02-04T15:05:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grzegorz\_Nosek](https://avatars.discourse-cdn.com/v4/letter/g/5daacb/32.png) [@Grzegorz\_Nosek](https://forum.ansible.com/u/Grzegorz_Nosek)\
**Post date:** [February 4, 2014, 3:05pm UTC](https://forum.ansible.com/t/best-practices-for-host-aliases/14487/1 "2014-02-04T15:05:09Z")

</div>

Hi,

Are there any generally accepted best practices regarding host aliases?  
E.g. I have a bunch of similar environments (dev/stage/prod or different  
customers with similar setups or whatever) where different machines play  
the same roles. For example:

# inventory:

somehost1.example.com  
somehost2.example.com  
somehost3.example.com

[vpn\_hub]  
somehost1.example.com

[vpn\_client]  
somehost2.example.com  
somehost3.example.com

# in a top level playbook

- hosts: vpn\_hub  
&nbsp;&nbsp;&nbsp;roles:  
&nbsp;&nbsp;&nbsp;- vpn\_hub  
- hosts: vpn\_client  
&nbsp;&nbsp;&nbsp;roles:  
&nbsp;&nbsp;&nbsp;- vpn\_client

# in a playbook for the vpn\_client role:

- name: generate vpn cert  
&nbsp;&nbsp;&nbsp;delegate\_to: groups.vpn\_hub[0]

# in a template (for the vpn\_client role too)

remote {{ groups.vpn\_hub[0].ansible\_default\_ipv4.address }}

I want neither the machine to be called vpn\_hub everywhere, nor to  
hardcode somehost1.example.com in playbooks, but the groups.vpn\_hub[0]  
is ugly. Is there a better way?

Best regards,  
&nbsp;&nbsp;Grzegorz Nosek
