# Ansible - Dynamicaly update /etc/hosts

DevFeed: [Ansible - Dynamicaly update /etc/hosts](<https://devfeed.tech/articles/ansible-dynamicaly-update-etc-hosts-27595.md>)

Original publisher: [Read original article](<https://gagor.pro/2013/12/ansible-dynamicaly-update-/etc/hosts/>)

Author: Tom

Published: 2013-12-11T00:00:00Z

Content type: tutorial

Language: en

Sources: [Tomasz Gągor](<https://devfeed.tech/sources/tomasz-gagor.md>)

Topics: [Ansible](<https://devfeed.tech/topics/ansible.md>), [servers](<https://devfeed.tech/topics/servers.md>), [configuration](<https://devfeed.tech/topics/configuration.md>)

Tags: [ansible](<https://devfeed.tech/tags/ansible.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [devops](<https://devfeed.tech/tags/devops.md>), [linux](<https://devfeed.tech/tags/linux.md>), [servers](<https://devfeed.tech/tags/servers.md>), [update](<https://devfeed.tech/tags/update.md>)

## AI overview

A short Ansible example shows how to update /etc/hosts with hostnames and IPv4 addresses from a server group while configuring GlusterFS.

## Source excerpt

I was configuring GlusterFS on few servers using Ansible external link and have a need to update /etc/hosts with hostnames for easier configuration. I found this1 one working: - name: Update /etc/hosts lineinfile: dest=/etc/hosts regexp='.*{{item}}$' line='{{hostvars.{{item}}.ansible_default_ipv4.address}} {{item}}' state=present with_items: '{{groups.somegroup}}' http://xmeblog.blogspot.com/2013/06/ansible-dynamicaly-update-etchosts.html external link ↩︎