Add or remove entries in /etc/hosts using tasks: - host: ip=127.0.0.1 hostname=localhost aliases=foobar.com,localhost.foobar.com - host: ip=127.0.0.1 hostname=localhost state=present - host: ip=192.168.1.1 state=absent - host: hostname=localhost state=absent - host: ip=::1 hostname=localhost aliases=ip6-localhost,ip6-loopback