Closed numenic closed 3 years ago
I usually use this workaround :
- name: modify /etc/hosts 127.0.1.1
when: ansible_hostname != hostname
lineinfile:
dest: /etc/hosts
regexp: '^(127\.0\.1\.1[ \t]+).*$'
line: '\1{{ hostname }}'
state: present
backrefs: yes
Hi, thanks for the issue. Interesting... I'm not sure that it's normal to add the hostname for 127.0.0.1
on a Linux system, I'm not sure why Ubuntu wants that, but I don't think it should need it...
Nevertheless, we are using cloud-init
to configure the system which is what's setting all of the hostname information, so we just do whatever Ubuntu has configured cloud-init
to do. I think if Ubuntu needs the system to have the hostname resolve to localhost (rather than say, what your DNS says it should be), then they probably need to configure cloud-init
to do that, then you'll get it for free on boot.
Have you seen this actually cause you a problem on an Ubuntu machine? If so, it might be a good idea to put in an upstream Ubuntu bug and ask them to modify cloud-init
to add the hostname to /etc/hosts
also.
(And just to clarify, you mentioned that /etc/hostname
does not get populated in your original comment, but your code snippet is for /etc/hosts
, so I'm assuming the latter...)
I could put in an option to let you run any custom scripts that you want in cloud-init
if you like. This way you could just set custom scripts as a part of your inventory, rather than a separate job?
you're right, it was /etc/hosts that is populated later on.
regarding real-world issue with this strange Ubuntu habits, I had yesterday an issue (sudo
didn't work properly), but I cannot reproduce it anymore...
For now, don't bother with cloud-init
stuff. Maybe we can close this, and I will reopen if I find a way to reproduce it?
Thanks anyway to have taken this in consideration, and pointed me to this cloud-init I should deep in.
Sure, can close for now. Thanks!
When setting ubuntu Guests (tested with 20.04), guest's hostname are not properly set:
ansible 4.4.0 (core 2.11.4)
tests.yml :
running tests.yml: ansible-playbook virt-infra.yml --limit kvmhost,tests
/etc/host
is correctly modified, but/etc/hostname
should also be modified (ref: https://askubuntu.com/a/1343976).By the way, great and impressive work!