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

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`)

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

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