# Is it possible to set the "hostname" in Ansible's console output?

**URL:** <https://forum.ansible.com/t/is-it-possible-to-set-the-hostname-in-ansibles-console-output/25967>\
**Category:** Ansible Project\
**Created:** [November 9, 2017, 1:38am UTC](https://forum.ansible.com/t/is-it-possible-to-set-the-hostname-in-ansibles-console-output/25967 "2017-11-09T01:38:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Fisher](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@Ryan\_Fisher](https://forum.ansible.com/u/Ryan_Fisher)\
**Post date:** [November 9, 2017, 1:38am UTC](https://forum.ansible.com/t/is-it-possible-to-set-the-hostname-in-ansibles-console-output/25967/1 "2017-11-09T01:38:32Z")

</div>

I’m creating a dynamic inventory using ec2.py (which is working great, thanks!). One minor annoyance I’m running into is that the console output that shows changes is labeled with the instances private IPs (as set by **hostname\_variable** or **[vpc\_]destination\_variable**). It would be nice to label these instances based on tags or the ec2 vars (or combination). From what I can tell, that isn’t possible because:

1. **hostname\_variable** only supports tags (not formatting or the ec2\_\* vars)
2. **destination\_format** overrides **vpc\_destination\_variable**  
I can modify ec2.py to add the functionality I’m looking for to **hostname\_variable** , just wondering if there was a supported method for doing this already.

Thanks!

---

<div class="post-metadata">

**Author:** ![Ryan\_Fisher](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@Ryan\_Fisher](https://forum.ansible.com/u/Ryan_Fisher)\
**Post date:** [November 9, 2017, 10:03pm UTC](https://forum.ansible.com/t/is-it-possible-to-set-the-hostname-in-ansibles-console-output/25967/2 "2017-11-09T22:03:08Z")

</div>

After further evaluation, I’ve found a way to achieve my desired result. However, look at the code makes me think that it’s not exactly intended…

What I’ve done:

**destination\_variable = private\_ip\_address**

**vpc\_destination\_variable = private\_ip\_address**

**destination\_format = {0}@{1}**  
**destination\_format\_tags = Name,private\_ip\_address**

This lets me set the ansible\_hostname (or maybe it’s inventory\_hostname) to the label I want (instance\_name@ip). However, ansible\_ssh\_host is then set to that same label, which isn’t the correct SSH connection IP. So in my inventory, I reset ansible\_ssh\_host like so:

**[all:vars]**  
**ansible\_ssh\_host={{ ec2\_private\_ip\_address }}**

Willing to be this will break something at some point if for no reason but that when **destination\_format** is used it doesn’t run the name through the **to\_safe** method in **ec2.py**.

---

<div class="post-metadata">

**Author:** ![Ryan\_Fisher](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@Ryan\_Fisher](https://forum.ansible.com/u/Ryan_Fisher)\
**Post date:** [November 9, 2017, 10:40pm UTC](https://forum.ansible.com/t/is-it-possible-to-set-the-hostname-in-ansibles-console-output/25967/3 "2017-11-09T22:40:29Z")

</div>

Seems like this is actually a known issue for dynamic inventories. My workaround will break when the depreciated **ansible\_ssh\_host** var is no longer supported.

Note, it is possible to override **ansible\_host** from the command line with **–extra-vars** which may end up being the better workaround in my case.

[https://github.com/ansible/ansible/issues/18359#issuecomment-267540204](https://github.com/ansible/ansible/issues/18359#issuecomment-267540204)

---

<div class="post-metadata">

**Author:** ![Ryan\_Fisher](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@Ryan\_Fisher](https://forum.ansible.com/u/Ryan_Fisher)\
**Post date:** [November 10, 2017, 5:51pm UTC](https://forum.ansible.com/t/is-it-possible-to-set-the-hostname-in-ansibles-console-output/25967/4 "2017-11-10T17:51:56Z")

</div>

And I’m wrong…

Use **–extra-vars** to override host vars: [https://github.com/ansible/ansible/issues/18359#issuecomment-343341692](https://github.com/ansible/ansible/issues/18359#issuecomment-343341692)
