Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building of /etc/hosts includes wrong data #10

Closed
hut8 opened this issue Jan 24, 2016 · 4 comments · Fixed by #15
Closed

Building of /etc/hosts includes wrong data #10

hut8 opened this issue Jan 24, 2016 · 4 comments · Fixed by #15

Comments

@hut8
Copy link
Contributor

hut8 commented Jan 24, 2016

I've only been using this role when deploying to a single host. Recently that changed, and after I fixed #3 I noticed this in my /etc/hosts:

127.0.0.1       localhost
127.0.1.1       ibm704
...
1.2.3.4 ibm704.example.com ibm704
4.3.2.1 ibm704.example.com therac25

Yikes 😲 My two hosts are ibm704.example.com and therac25.example.com. So the last line above should clearly be therac25.example.com instead of ibm704.example.com right? I just upgraded the role.

hut8 added a commit to tenex/opensourcecontributors that referenced this issue Jan 24, 2016
@holms
Copy link
Owner

holms commented Jan 25, 2016

Your pull request is the last in here: #3
You're welcome to fix this issue :)

@johnjelinek
Copy link

👍

@hut8
Copy link
Contributor Author

hut8 commented Jan 30, 2016

My speculation on cause (disclaimer: I have no idea about the guts of Ansible):

https://github.com/holms/ansible-fqdn/blob/master/tasks/default.yml#L12

- name: Build hosts file (backups will be made)
  lineinfile: dest=/etc/hosts line='{{ hostvars[item].ansible_default_ipv4.address }} {{ fqdn }} {{ hostvars[item].ansible_hostname }}' state=present backup=yes
  when: hostvars[item].ansible_default_ipv4.address is defined
  with_items: groups['all']

Here, {{ fqdn }} remains constant throughout this loop -- it's the fqdn variable set in the playbook for a particular host (call that host "awesome_host.example.com"). Then this loops through each host, and pairs hostvars[item].ansible_default_ipv4.address with fqdn, which doesn't change in the body of the loop. A couple days ago I tried to figure out how you can get a role's variable for a different host in a play and couldn't find anything, then I gave up. That's my progress.

it's something

@hut8
Copy link
Contributor Author

hut8 commented Jan 30, 2016

Separate note: I don't really see why this part of this (generating /etc/hosts with all hosts in the same playbook) is necessary or even desirable. Say you're dealing with a playbook with asset hosts specifically. If you are already have some sites at example1.com and example2.com, and now you want to add some assets servers with FQDNs like "assets.example1.com" and "assets.example2.com", then I do believe each host should resolve "assets" to itself. But in this case, it seems like there's going to be a line added for both default IP addresses in which "assets", queried alone, might return any of them. But it won't return other hosts in the same domain, which is probably what you wanted.

I feel like this could be removed/factored out into another role.

Thoughts from @holms ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants