Skip to content
This repository has been archived by the owner on Apr 19, 2019. It is now read-only.

Hosts file can generate duplicate entry weirdness #13

Closed
d34dh0r53 opened this issue Aug 29, 2014 · 6 comments · Fixed by #17
Closed

Hosts file can generate duplicate entry weirdness #13

d34dh0r53 opened this issue Aug 29, 2014 · 6 comments · Fixed by #17

Comments

@d34dh0r53
Copy link
Contributor

If you remove containers/re-run ansible duplicate hosts will be creating leading to very inconsistent and weird results:

root@533812-node16:~/ansible-lxc-rpc/rpc_deployment# grep 222 /etc/hosts
10.241.0.222 infra3_horizon_container-b0288493
10.241.0.222 infra3_heat_apis_container-a7ee79ee
@d34dh0r53
Copy link
Contributor Author

andymcc: I'm not sure we can fix this in a sensible way since some hosts will have the same IP (nova-compute and a physical host, for example) - I think we are better off investigating how to prevent "unmanaged" nodes (nodes not in the inventory) from existing. So guarding against having 2 different inventory files (different sets of containers on the same IPs etc).

@d34dh0r53
Copy link
Contributor Author

apsu: It might help to provide another bit of context to consider here.

Ansible used to ship a "host" module which would attempt to manage your /etc/hosts file for you. Our own dear claco pointed out an issue with how it handled aliases -- exactly as you're seeing even with just lineinfile -- and the module got pulled from Ansible and hasn't yet been replaced.

The usual solution I see in playbooks for dealing with /etc/hosts is to use a template and render it with exactly the contents that host should have, rather than lineinfile.

That said... if you Want the old host module to poke at, I actually have it stashed away in my ansible fork I use with my dockerlab/virtlab repos, since I find it useful for most /etc/hosts tasks. It's located here: https://github.com/Apsu/ansible/blob/dockerlab/library/system/host

@d34dh0r53
Copy link
Contributor Author

claco: Some people who have simple needs, use the 'line in file' module with regex/replace.

@d34dh0r53
Copy link
Contributor Author

andymcc: PR'd against this on new repo #1

@d34dh0r53
Copy link
Contributor Author

andymcc: Fixed in local branch: Fixed in local branch: https://github.com/andymcc/ansible-lxc-rpc/tree/hosts_duplicate

@d34dh0r53
Copy link
Contributor Author

Can this issue be closed?

andymcc added a commit to andymcc/ansible-lxc-rpc that referenced this issue Sep 1, 2014
Adds to tasks in the updatehostsfile play that will do the following to the
/etc/hosts file:
* Removes any entries that match the IP of current host, but with a different
  hostname
* Removes any entries that match the hostname of the current host but with a
  different IP

This will prevent duplicate entries and other /etc/hosts file related
strangeness.

Fixes rcbops#13
andymcc added a commit to andymcc/ansible-lxc-rpc that referenced this issue Sep 1, 2014
Adds to tasks in the updatehostsfile play that will do the following to
the /etc/hosts file:
* Removes any entries that match the IP of current host, but with a
  different hostname
* Removes any entries that match the hostname of the current host but
  with a different IP

This will prevent duplicate entries and other /etc/hosts file related
strangeness.

Fixes rcbops#13
andymcc added a commit to andymcc/ansible-lxc-rpc that referenced this issue Sep 3, 2014
Adds to tasks in the updatehostsfile play that will do the following to the
/etc/hosts file:
* Removes any entries that match the IP of current host, but with a different
  hostname
* Removes any entries that match the hostname of the current host but with a
  different IP

This will prevent duplicate entries and other /etc/hosts file related
strangeness.

Fixes rcbops#13
mancdaz pushed a commit to mancdaz/ansible-lxc-rpc that referenced this issue Oct 13, 2014
Adds to tasks in the updatehostsfile play that will do the following to the
/etc/hosts file:
* Removes any entries that match the IP of current host, but with a different
  hostname
* Removes any entries that match the hostname of the current host but with a
  different IP

This will prevent duplicate entries and other /etc/hosts file related
strangeness.

Fixes rcbops#13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants