Closed isuftin closed 5 days ago
Ran into it as well.
The problem is here:
This file assumes Jinja templating for the port parameter and passes a Jinja-style "{{ port }}".
https://github.com/ansible/molecule/blob/main/src/molecule/command/login.py#L105
^ Now this happens in this file and is done by python calling .format()
on the string. That effectively means we need python-style templates (so "{var}") and not Jinja (double brackets - "{{ var }}".
I submitted an MR here to fix this up: https://github.com/ansible-community/molecule-plugins/pull/240
@danielpodwysocki - Glad it's not just me. Appreciate the MR.
reproduced using vagrant + virtualbox. https://github.com/konstruktoid/ansible-role-hardening/blob/master/molecule/almalinux/molecule.yml
$ molecule login -s almalinux --host almalinux8
WARNING Driver vagrant does not provide a schema.
WARNING Driver vagrant does not provide a schema.
WARNING Driver docker does not provide a schema.
WARNING Driver vagrant does not provide a schema.
WARNING Driver vagrant does not provide a schema.
WARNING Driver vagrant does not provide a schema.
WARNING Driver vagrant does not provide a schema.
INFO Running almalinux > login
Bad port '{port}'
$ ssh -i [...]/ansible-role-hardening/almalinux/.vagrant/machines/almalinux8/virtualbox/private_key vagrant@127.0.0.1 -p2222
By accessing this system, you consent to the following conditions:
- This system is for authorized use only.
- Any or all uses of this system and all files on this system may be monitored.
- Communications using, or data stored on, this system are not private.
Last login: Fri Feb 16 11:21:52 2024 from 10.0.2.2
[vagrant@almalinux8 ~]$
# Molecule managed
---
all:
hosts:
almalinux8: &id001
ansible_host: 127.0.0.1
ansible_port: '2222'
ansible_private_key_file: [...]/.cache/molecule/ansible-role-hardening/almalinux/.vagrant/machines/almalinux8/virtualbox/private_key
ansible_ssh_common_args: -o UserKnownHostsFile=/dev/null -o ControlMaster=auto
-o ControlPersist=60s -o ForwardX11=no -o LogLevel=ERROR -o IdentitiesOnly=yes
-o StrictHostKeyChecking=no
ansible_user: vagrant
connection: ssh
almalinux9: &id002
ansible_host: 127.0.0.1
ansible_port: '2200'
ansible_private_key_file: [...]/.cache/molecule/ansible-role-hardening/almalinux/.vagrant/machines/almalinux9/virtualbox/private_key
ansible_ssh_common_args: -o UserKnownHostsFile=/dev/null -o ControlMaster=auto
-o ControlPersist=60s -o ForwardX11=no -o LogLevel=ERROR -o IdentitiesOnly=yes
-o StrictHostKeyChecking=no
ansible_user: vagrant
connection: ssh
vars:
molecule_ephemeral_directory: '{{ lookup(''env'', ''MOLECULE_EPHEMERAL_DIRECTORY'')
}}'
molecule_file: '{{ lookup(''env'', ''MOLECULE_FILE'') }}'
molecule_instance_config: '{{ lookup(''env'', ''MOLECULE_INSTANCE_CONFIG'') }}'
molecule_no_log: '{{ lookup(''env'', ''MOLECULE_NO_LOG'') or not molecule_yml.provisioner.log|default(False)
| bool }}'
molecule_scenario_directory: '{{ lookup(''env'', ''MOLECULE_SCENARIO_DIRECTORY'')
}}'
molecule_yml: '{{ lookup(''file'', molecule_file) | from_yaml }}'
ungrouped:
hosts:
almalinux8: *id001
almalinux9: *id002
vars: {}
$ molecule --version
molecule 24.2.0 using python 3.11
ansible:2.16.3
azure:23.5.3 from molecule_plugins
containers:23.5.3 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
default:24.2.0 from molecule
docker:23.5.3 from molecule_plugins requiring collections: community.docker>=3.4.11 ansible.posix>=1.4.0
ec2:23.5.3 from molecule_plugins
gce:23.5.3 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
openstack:23.5.3 from molecule_plugins requiring collections: openstack.cloud>=2.1.0
podman:23.5.3 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
vagrant:23.5.3 from molecule_plugins
I am seeing this issue crop up in 23.5.3 where molecule login fails with the Bad Port error mentioned above. However, this does not occur with version 23.5.0.
I do not see any difference in the code for molecule login between these two versions.
Is this a regression bug and was it in 23.5.0?
I updated the PR to cover all plugins, it seems this affects each one of them.
Seeing this as well with the GCE driver.
Ran into it as well.
I submitted an MR here to fix this up: #240
Thanks for the analysis and fix. I applied the change you posted in the PR for the vagrant driver and all is now working.
hey @ssbarnea or @zhan9san could you have a look at PR #240 ? Thanks
It seems that molecule dropped support for init (see https://github.com/ansible/molecule/discussions/4042), so I downgraded to molecule 5.1 and everything worked fine.
However, as suggested from IRC I tried to upgrade molecule and removed the files created on initialization of scenario (create.yml
and destroy.yml
), and then my vagrant machine booted fine. However, I could no login because of this issue ('Bad port').
ansible-community#239 fixes this issue with the last version of molecule, but then it fails with molecule 5.1.
@ssbarnea
Using Molecule on MacOS ventura 13.6.4
This seems to be a new issue for me, but when using molecule to test against a remote EC2 instance, when I run "molecule login -s my_scenario", I get
Bad port '{port}'
Molecule converge seems to work fine.
Scenario specific configuration:
ansible_inventory.yml
ansible.cfg
instance_config.yml
molecule.yml
I can use the ssh key defined in the inventory along with the ip address and SSH into the instance manually with no issues.