Ansible-native inventory fails with list and login

I am trying to get molecule-plugins[podman] working with ansible-native inventory.

molecule.yml:

---
ansible:
  cfg:
    defaults:
      deprecation_warnings: false
      host_key_checking: false
  env:
    ANSIBLE_ROLES_PATH: ../../../playbooks/roles
    ANSIBLE_INVENTORY: inventory/

  executor:
    args:
      ansible_playbook:
        - --inventory=inventory/
dependency:
  name: galaxy
  options:
    requirements-file: ${MOLECULE_SCENARIO_DIRECTORY}/requirements.yml

scenario:
  test_sequence:
    - dependency
    - destroy
    - create
    - converge
    - idempotence
    - verify
    - cleanup
    - destroy

hostsfile:

---
all:
  children:
    molecule:
      hosts:
        molecule-ubuntu2404:
          container_image: docker.io/geerlingguy/docker-ubuntu2404-ansible
          ansible_connection: podman
        molecule-ubuntu2204:
          container_image: docker.io/geerlingguy/docker-ubuntu2204-ansible
          container_command: sleep 1d
          container_privileged: false
          ansible_connection: podman

The create/converge/… all works however list and login fails.
podman ps and List shows following:

⭐❯ podman ps
CONTAINER ID  IMAGE                                                   COMMAND     CREATED      STATUS         PORTS       NAMES
9e8ceadf39dd  docker.io/geerlingguy/docker-ubuntu2404-ansible:latest  sleep 1d    11 days ago  Up 34 minutes              molecule-ubuntu2404
d79b3ff0e793  docker.io/geerlingguy/docker-ubuntu2204-ansible:latest  sleep 1d    11 days ago  Up 34 minutes              molecule-ubuntu2204
⭐❯ molecule list -s default
INFO     default ➜ list: Executing
INFO     default ➜ list: Executed: Successful
                β•·             β•·                  β•·               β•·         β•·            
  Instance Name β”‚ Driver Name β”‚ Provisioner Name β”‚ Scenario Name β”‚ Created β”‚ Converged  
╢───────────────┼─────────────┼──────────────────┼───────────────┼─────────┼───────────╴
                β”‚ default     β”‚ ansible          β”‚ default       β”‚ true    β”‚ false      
                β•΅             β•΅                  β•΅               β•΅         β•΅            

molecule login shows following:

⭐❯ molecule login -s default -h molecule-ubuntu2404
INFO     default ➜ login: Executing
ERROR    Unable to find host 'molecule-ubuntu2404'.
For more information: https://docs.ansible.com/projects/molecule/usage/#molecule-login

Am I missing elements? Am I doing anything wrong?

I had the same problem and decided after long while to systematically reverse engineer the problem.

If you put a debugger to this line: molecule/src/molecule/command/login.py at 1cbcd4f68d35957ee3de41b5b27992b85d1d6050 Β· ansible/molecule Β· GitHub

you’ll see that it is looking to self._config.platforms.instances
and that’s how ansible molecule is figuring out which instances do exist that it could login.

So, it’s not doing a live lookup vs podman nor a lookup into your inventory.
It’s just a configuration like in the example for docker Using docker containers - Ansible Molecule that seems to be forgotten in the documentation for podman.

I added to my molecule/default-podman/molecule.yml now these lines:

platforms:

  • name: molecule-fedora
    image: ghcr . io /ansible/community-ansible-dev-tools:latest # remove whitespace (is detected as url and there’s a limit for anything looking like a url)

for the example of podman from the documentation and now the login works.

You probably would have to adopt it to something like (untested):

platforms

  • name: molecule-ubuntu2404
    image: docker . io / geerlingguy/docker-ubuntu2404-ansible # remove whitespaces
  • name: molecule-ubuntu2204
    image: docker . io/geerlingguy/docker-ubuntu2204-ansible # remove whitespaces

Quite tricky and I knew why I tested it before starting my new work :slight_smile:
The whole documentation seems to be inconsistent and in addition pretty much all tutorials also don’t work out of the box with current ansible / molecule variations. (If you take older versions from several years ago, it seems to work, even though I don’t see a change regarding the source code in the last 6 years). But I won’t investigate that.

I already got paranoid whether it’s a RHEL move similar to what Microslop loves to do, because I only tested it so far from control hosts with debian / ubuntu.

The strange thing also is that molecule init doesn’t create the platforms configuration either.
Without debugging on patching the libraries in my venv I would not have found that.

Can we really trust to use this for production if it works that subtle?
Anyway, I hope it helps you and maybe the next poor guy who runs into this topic.

1 Like