# replace public ip from /etc/hosts file with private ip using Ansible

**URL:** <https://forum.ansible.com/t/replace-public-ip-from-etc-hosts-file-with-private-ip-using-ansible/22406>\
**Category:** Ansible Project\
**Created:** [August 27, 2016, 4:26pm UTC](https://forum.ansible.com/t/replace-public-ip-from-etc-hosts-file-with-private-ip-using-ansible/22406 "2016-08-27T16:26:16Z")\
**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 27, 2016, 4:26pm UTC](https://forum.ansible.com/t/replace-public-ip-from-etc-hosts-file-with-private-ip-using-ansible/22406/1 "2016-08-27T16:26:16Z")

</div>

I need to replace public ip from /etc/hosts file with private ip in bulk cluster of systems.  
Ansible gathered fact , may work but not sure which is for what.

Another way, I can have public and private ip register as variable and swap them.

What would be the best practice to do in ansible way?

Currently in /etc/hosts
