I would like to update /etc/hosts file using ansible playbook to all my 50 servers.
<ipaddress> <fqdn> <hostname>
I would like to update /etc/hosts file using ansible playbook to all my 50 servers.
<ipaddress> <fqdn> <hostname>
Such a task is a good starting point for learning. So it was one of the first tasks I've implement in my own playbooks.
- name: Make sure an entry in /etc/hosts exists
lineinfile:
path: /etc/hosts
regexp: "^{{ ansible_default_ipv4.address }}"
line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }} {{ ansible_hostname }}"
state: present
tags: network,hostname,dns
Depending on your environment and configuration you might be able to use also
{{ ansible_eth0.ipv4.address }}
Other useful variables in this case are
{{ ansible_domain }}
{{ ansible_default_ipv6.address }}
I leave further research and testing to you.