# replacing public ip with private in /etc/hosts

**URL:** <https://forum.ansible.com/t/replacing-public-ip-with-private-in-etc-hosts/22396>\
**Category:** Ansible Project\
**Created:** [August 26, 2016, 1:50pm UTC](https://forum.ansible.com/t/replacing-public-ip-with-private-in-etc-hosts/22396 "2016-08-26T13:50:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Auto-mate](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@Auto-mate](https://forum.ansible.com/u/Auto-mate)\
**Post date:** [August 26, 2016, 1:50pm UTC](https://forum.ansible.com/t/replacing-public-ip-with-private-in-etc-hosts/22396/1 "2016-08-26T13:50:45Z")

</div>

I am trying to replace public ip with private ip in /etc/hosts for bulk of hosts .

Current setup

PUBLIC\_IP hostname shot\_hostname

Needed :

PRIVATE \_IP hostname short\_hostname

How I can do it using ansible? I wonder if it can be done using gathered facts by ansible?  
I would think of , getting the public ip and register as variable and same time get the private ip .  
Now, replacing it using replace or inline module. Any best approach ?
