# fetch module - hostname instead of ip in the filesystem tree?

**URL:** <https://forum.ansible.com/t/fetch-module-hostname-instead-of-ip-in-the-filesystem-tree/16575>\
**Category:** Ansible Project\
**Created:** [October 21, 2014, 8:27pm UTC](https://forum.ansible.com/t/fetch-module-hostname-instead-of-ip-in-the-filesystem-tree/16575 "2014-10-21T20:27:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Warkentin](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Michael\_Warkentin](https://forum.ansible.com/u/Michael_Warkentin)\
**Post date:** [October 21, 2014, 8:27pm UTC](https://forum.ansible.com/t/fetch-module-hostname-instead-of-ip-in-the-filesystem-tree/16575/1 "2014-10-21T20:27:30Z")

</div>

Hello, I was wondering if there’s any way to use the hostname of a server rather than it’s IP to generate the file system tree when using the fetch module?

Our ansible inventories are set up like so:

aqua-notif-wrkr-01 ansible\_ssh\_host=12.34.56.789

This ends up generating a tree like this: [https://s3.amazonaws.com/snaps.michaelwarkentin.com/generate\_server\_list.py\_\_waveapps\_2014-10-21\_16-17-17.png](https://s3.amazonaws.com/snaps.michaelwarkentin.com/generate_server_list.py__waveapps_2014-10-21_16-17-17.png)

Would setting up /etc/hosts to map hostnames to IPs work, or are we stuck with this?

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [October 23, 2014, 3:52pm UTC](https://forum.ansible.com/t/fetch-module-hostname-instead-of-ip-in-the-filesystem-tree/16575/2 "2014-10-23T15:52:04Z")

</div>

Hi Michael,

One way you can get around this is to use the inventory\_hostname variable in the dest= along with flat=yes, as follows:

- hosts: all  
gather\_facts: no  
tasks:
- fetch: src=/etc/hosts dest=“/tmp/{{inventory\_hostname}}/” flat=yes

As long as the inventory\_hostname is actually a hostname and not an IP, this should do what you need. Beyond that, you can open a feature request PR on ansible-modules-core to allow using the inventory hostname instead of the connection address, when available.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Michael\_Warkentin](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Michael\_Warkentin](https://forum.ansible.com/u/Michael_Warkentin)\
**Post date:** [October 24, 2014, 1:19pm UTC](https://forum.ansible.com/t/fetch-module-hostname-instead-of-ip-in-the-filesystem-tree/16575/3 "2014-10-24T13:19:11Z")

</div>

Thanks James, I’ll give that a try!

Sorry about the double-post as well - I didn’t realize that the forum was moderated, so I thought there was a glitch when I submitted my first message.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 24, 2014, 1:42pm UTC](https://forum.ansible.com/t/fetch-module-hostname-instead-of-ip-in-the-filesystem-tree/16575/4 "2014-10-24T13:42:46Z")

</div>

“if there’s any way to use the hostname of a server rather than it’s IP to generate the file system tree when using the fetch module?”

Yeah, It should use the inventory name anyway.

I’d file a bug on this one at [github.com/ansible/ansible](http://github.com/ansible/ansible) – it’s a small bug, and the workaround above will do, but it shouldn’t be using conn.host as the host path, but rather “inventory\_hostname”.

---

<div class="post-metadata">

**Author:** ![Michael\_Warkentin](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Michael\_Warkentin](https://forum.ansible.com/u/Michael_Warkentin)\
**Post date:** [October 24, 2014, 3:20pm UTC](https://forum.ansible.com/t/fetch-module-hostname-instead-of-ip-in-the-filesystem-tree/16575/5 "2014-10-24T15:20:17Z")

</div>

Hey Michael, thanks for the reply. I’ve opened [ansible#9415](https://github.com/ansible/ansible/issues/9415) to track this.
