# How to display ansible\_host in console output even if an alias is defined at inventory level

**URL:** <https://forum.ansible.com/t/how-to-display-ansible-host-in-console-output-even-if-an-alias-is-defined-at-inventory-level/26576>\
**Category:** Ansible Project\
**Created:** [January 28, 2018, 5:17am UTC](https://forum.ansible.com/t/how-to-display-ansible-host-in-console-output-even-if-an-alias-is-defined-at-inventory-level/26576 "2018-01-28T05:17:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julio\_Fernandez](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Julio\_Fernandez](https://forum.ansible.com/u/Julio_Fernandez)\
**Post date:** [January 28, 2018, 5:17am UTC](https://forum.ansible.com/t/how-to-display-ansible-host-in-console-output-even-if-an-alias-is-defined-at-inventory-level/26576/1 "2018-01-28T05:17:42Z")

</div>

Hi everyone!

We currently use **ansible\_host** variable and define an alias for the hosts we use as follows:

Inventory file

```auto
[my_jboss_servers]
jboss_server1 ansible_host=myhostnameABC
jboss_server2 ansible_host=myhostnameEFG
jboss_server3 ansible_host=myhostnameHIJ
jboss_server4 ansible_host=myhostnameKLM

```

The reason for this is because hosts might change from time to time and since we have host-specific variables and files, it’s just easier to keep using the same alias so we don’t have to change any file names in our repository however this also has a disadvantage as it might get confusing if we start removing and adding hosts since the ansible-playbook console output displays only the alias, not the actual host, see:

```auto
$ ansible-playbook myplaybook.yml -i inventory/my_inventory

PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [jboss_server1]
ok: [jboss_server2]
ok: [jboss_server3]
ok: [jboss_server4]

TASK [Task 1 : Create home directory if it does not exist] *******************
ok: [jboss_server1]
ok: [jboss_server2]
ok: [jboss_server3]
ok: [jboss_server4]

```

My questions are:

1. Is there any ansible best-practice on how to handle this scenario?
2. Is there any way I can display the actual hostname, not the alias in the console output?

Thanks in advance for your help / guidance on this!

---

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [January 28, 2018, 4:55pm UTC](https://forum.ansible.com/t/how-to-display-ansible-host-in-console-output-even-if-an-alias-is-defined-at-inventory-level/26576/2 "2018-01-28T16:55:58Z")

</div>

I think it's best to reserve ansible\_host as the IP address as that remains constant. You can declare friendly names first that way:

jboss\_1 ansible\_host=10.0.0.10

Going by your method, your inventory will require a lot of upkeep because if the hostname changes, the inventory will break.

---

<div class="post-metadata">

**Author:** ![Julio\_Fernandez](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Julio\_Fernandez](https://forum.ansible.com/u/Julio_Fernandez)\
**Post date:** [January 28, 2018, 6:10pm UTC](https://forum.ansible.com/t/how-to-display-ansible-host-in-console-output-even-if-an-alias-is-defined-at-inventory-level/26576/3 "2018-01-28T18:10:08Z")

</div>

Thanks, Varun!

Got it, but even so, imagine that we suddenly remove one of the so the inventory would initially look like this:

Inventory file

```auto
[my_jboss_servers]
jboss_server1 ansible_host=IP1
jboss_server3 ansible_host=IP3
jboss_server4 ansible_host=IP4

```

And if I run the playbook, I’ll see something like this:

```auto
$ ansible-playbook myplaybook.yml -i inventory/my_inventory

PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [jboss_server1]
ok: [jboss_server3]
ok: [jboss_server4]

TASK [Task 1 : Create home directory if it does not exist] *******************
ok: [jboss_server1]
ok: [jboss_server3]
ok: [jboss_server4]

```

Which I think might be confusing, initially as the first question would be: “what abour jboss\_server2”? so I guess I’m trying to find a way to balance both, maintenance and clarity

Regards.

---

<div class="post-metadata">

**Author:** ![Russell\_Yorke](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Russell\_Yorke](https://forum.ansible.com/u/Russell_Yorke)\
**Post date:** [January 29, 2018, 2:21am UTC](https://forum.ansible.com/t/how-to-display-ansible-host-in-console-output-even-if-an-alias-is-defined-at-inventory-level/26576/4 "2018-01-29T02:21:50Z")

</div>

Hey

Why not put a debug statement at the beginning of your play that outputs the ansible\_hostname? That way you can a one-to-one mapping in your output and you can reference that to figure out what system each refers to? Just a thought.
