molecule
molecule copied to clipboard
molecule removes `_` from hostname: `sudo: unable to resolve host`
HAPPY NEW YEAR! And thanks for making and maintaining Molecule. My wished for 2022: Keep up the exceptional work!
Issue Type
- Bug report
Molecule and Ansible details
ansible --version && molecule --version
ansible [core 2.11.1]
config file = None
configured module search path = ['/Users/robertdb/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /opt/homebrew/lib/python3.9/site-packages/ansible
ansible collection location = /Users/robertdb/.ansible/collections:/usr/share/ansible/collections
executable location = /opt/homebrew/bin/ansible
python version = 3.9.2 (default, Mar 26 2021, 15:28:17) [Clang 12.0.0 (clang-1200.0.32.29)]
jinja version = 2.11.3
libyaml = True
molecule 3.3.0 using python 3.9
ansible:2.11.1
delegated:3.3.0 from molecule
docker:0.2.4 from molecule_docker
Molecule installation method (one of):
- pip
Ansible installation method (one of):
- pip
Detail any linters or test runners used:
Desired Behaviour
Some roles have an underscore _ in the name, like ansible-role-python_pip. Molecule should not change the hostname, I think it does.
Actual Behaviour
Molecule removes the _ from the hostname. This can cause an issue with sudo:
sudo: unable to resolve host pythonpip-debian-bookwormpy39-ansible-2.11: Name or service not known
(So far, only debian:bookworm causes an issue, I guess the sudo is configured a bit more strict.)
This behaviour seems new, I checked the last few molecule releases, but could not find a related change. This makes me unsure if Molecule causes the issue or Debian (or sudo), so please let me know if you think it's something different than Molecule that causes the removal of the _ from the hostname.
(The full error.)
Reproduction
git clone [email protected]:robertdebock/ansible-role-python_pip.git
cd ansible-role-python_pip
molecule test --destroy=never
molecule login
hostname
sudo ls
I did habe troubles with underscores in hostnames before. According to RFC 952 underscores are not valid, and I think that some versions of linux (glibc?) follow that more strictly than others.
A "name" (Net, Host, Gateway, or Domain name) is a text string up
to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus
sign (-), and period (.).
That said, I am not sure that the issue is caused by molecule.
That said, I am not sure that the issue is caused by molecule.
I agree, it's not really molecule, on the other hand, I would not know how to proceed with it now...
FWIW, I managed to trigger the sudo error without using molecule. It happens when there is no entry in /etc/hosts in the container.
I created my test container with podman run --no-hosts ... -> /etc/hosts does not exist at all, and after installing python and sudo and creating a user, when connecting there is the sudo: unable to resolve host ... errror. After creating an entry in /etc/hosts ansible connection was working.
I found a blog post about this topic https://linuxhandbook.com/sudo-unable-resolve-host/
Thanks @mafalb, I am seeing this issue;
- The hostname is without
_. - The entry in
/etc/hostsis with_.
Have a look at a Docker instance that Molecule created:
root@pythonpip-debian-bookworm:/# cat /etc/hosts
# (non relevant lines removed)
172.17.0.6 python_pip-debian-bookworm
root@pythonpip-debian-bookworm:/# hostname
pythonpip-debian-bookworm
I wonder if Molecule can "fix" this as I'm not sure what sets the hostname.
For now, I'll remove the underscores from molecule/default/molecule.yml: platforms.name.
For future readers, this is BROKEN:
platforms:
- name: "some_name" # BROKEN, an underscore can give issues with setting the hostname.
This is WORKING:
platforms:
- name: "somename"