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

printing correct entries in /etc/hosts #3

Closed
ksingh7 opened this issue Jun 20, 2015 · 2 comments
Closed

printing correct entries in /etc/hosts #3

ksingh7 opened this issue Jun 20, 2015 · 2 comments

Comments

@ksingh7
Copy link

ksingh7 commented Jun 20, 2015

Hi , to get correct value in /etc/hosts you should use {{ hostvars[item].ansible_hostname }}.{{ fqdn }}

it will print in /etc/hosts as

10.188.0.47 one.csc.fi one ( IP FQDN HOSTNAME )

use below in default.yml

  lineinfile: dest=/etc/hosts regexp='{{ hostvars[item].ansible_hostname }}$' line='{{ hostvars[item].ansible_default_ipv4.address }} {{ hostvars[item].ansible_hostname }}.{{ fqdn }} {{ item }}' state=present backup=yes
@holms
Copy link
Owner

holms commented Jun 20, 2015

Can you do pull request? as far as I remember I've tried your method once, it wasn't working on debian I think, or in RHEL... when I did like it does now, it started to work.

@hut8
Copy link
Contributor

hut8 commented Dec 26, 2015

The way it's done now in this role doesn't seem to work on Debian:

% cat /etc/hosts 
127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
216.120.248.265 staging  staging.example.com
% hostname
staging
% hostname --fqdn
staging

This causes issues with mail (among other things). Of course I changed my server's address and hostname in the example.

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

No branches or pull requests

3 participants