# How to add a 'fake’ loopback alias with the public/elastic IP address

**URL:** <https://forum.ansible.com/t/how-to-add-a-fake-loopback-alias-with-the-public-elastic-ip-address/22136>\
**Category:** Ansible Project\
**Created:** [July 27, 2016, 12:35pm UTC](https://forum.ansible.com/t/how-to-add-a-fake-loopback-alias-with-the-public-elastic-ip-address/22136 "2016-07-27T12:35:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rohit\_Maheshwari1](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rohit\_Maheshwari1](https://forum.ansible.com/u/Rohit_Maheshwari1)\
**Post date:** [July 27, 2016, 12:35pm UTC](https://forum.ansible.com/t/how-to-add-a-fake-loopback-alias-with-the-public-elastic-ip-address/22136/1 "2016-07-27T12:35:46Z")

</div>

Hi Everyone,

I wanted to automate the below commands using ansible but I am facing difficulty to do that. Need your help.

**- Adding a ‘fake’ loopback alias with the public/elastic IP address:**

sudo cat \>\> /etc/sysconfig/network-scripts/ifcfg-lo:0 \<\< EOF

DEVICE=lo:0

IPADDR=`curl [http://instance-data/latest/meta-data/public-ipv4`]([http://instance-data/latest/meta-data/public-ipv4`](http://instance-data/latest/meta-data/public-ipv4%60))

NETMASK=255.255.255.255

ONBOOT=yes

NAME=loopback

EOF

- sudo systemctl restart network

**- DNS configuration:**

sudo mv /etc/resolv.conf /etc/resolv.conf.ori

sudo cat \>\> /etc/resolv.conf \<\< EOF

nameserver XX.XX.XX.XX

EOF

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [July 27, 2016, 5:06pm UTC](https://forum.ansible.com/t/how-to-add-a-fake-loopback-alias-with-the-public-elastic-ip-address/22136/2 "2016-07-27T17:06:33Z")

</div>

The first one is a template: task with a handler to restart the network  
The second is a lineinfile: task.
