molecule: 3.6.0 login to podman fails '/usr/bin/env /bin/podman' No such file

Issue Type

  • Bug report

Molecule and Ansible details

ansible --version
ansible [core 2.11.4] 
  config file = /home/indermue/src/ansible-mysql/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/ansible
  ansible collection location = /home/indermue/src/ansible-mysql/collections:/root/python-venv/ansible-4.2.0/lib/python3.8/site-packages:/var/lib/awx/projects/ansible-mysql-manual/collections:/opt/my-tower-venv/ansible-4.2.0/lib/python3.8/site-packages
  executable location = /root/python-venv/ansible-4.4.0/bin/ansible
  python version = 3.8.8 (default, Aug 11 2021, 06:52:42) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 3.0.1
  libyaml = True
molecule --version
molecule 3.6.0 using python 3.8
    ansible:2.11.4
    delegated:3.6.0 from molecule
    podman:1.1.0 from molecule_podman requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0

Molecule installation method (one of):

  • pip

Ansible installation method (one of):

  • pip

Desired Behavior

molecule login -h node -s scenario should open bash from within the podman container.

Actual Behaviour

Molecule fails to execute with the following error:

INFO     Inventory /home/indermue/src/ansible-mysql/molecule/mariadb/inventory/static.yml linked to /root/.cache/molecule/ansible-mysql/mariadb/inventory/hosts
INFO     Inventory /home/indermue/src/ansible-mysql/molecule/mariadb/inventory/group_vars linked to /root/.cache/molecule/ansible-mysql/mariadb/inventory/group_vars
INFO     Inventory /home/indermue/src/ansible-mysql/molecule/mariadb/inventory/host_vars linked to /root/.cache/molecule/ansible-mysql/mariadb/inventory/host_vars
INFO     Running mariadb > login 
Traceback (most recent call last):
  File "/root/python-venv/ansible-4.4.0/bin/molecule", line 8, in <module>
    sys.exit(main())
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/molecule/command/login.py", line 166, in login
    base.execute_subcommand(scenario.config, subcommand)
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/molecule/command/base.py", line 149, in execute_subcommand
    return command(config).execute()
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/molecule/logger.py", line 188, in wrapper
    rt = func(*args, **kwargs)
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/molecule/command/login.py", line 101, in execute
    self._get_login(hostname)
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/molecule/command/login.py", line 146, in _get_login
    app.runtime.exec(cmd)
  File "/root/python-venv/ansible-4.4.0/lib/python3.8/site-packages/ansible_compat/runtime.py", line 138, in exec
    result = run_func(
  File "/usr/lib64/python3.8/subprocess.py", line 493, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib64/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib64/python3.8/subprocess.py", line 1706, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/env /bin/podman exec -e COLUMNS=254 -e LINES=60 -e TERM=bash -e TERM=xterm -ti mariadb_104 bash'  

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I am having the same issue with the Docker driver:

> molecule --version
molecule 3.6.0 using python 3.9
    ansible:2.12.2
    delegated:3.6.0 from molecule
    docker:1.1.0 from molecule_docker requiring collections: community.docker>=1.9.1
    podman:1.1.0 from molecule_podman requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0

> molecule login
INFO     Running default > login
Traceback (most recent call last):
  File "/home/iinuwa/.local/bin/molecule", line 8, in <module>
    sys.exit(main())
  File "/home/iinuwa/.local/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/iinuwa/.local/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/iinuwa/.local/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/iinuwa/.local/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/iinuwa/.local/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/iinuwa/.local/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/iinuwa/.local/lib/python3.9/site-packages/molecule/command/login.py", line 166, in login
    base.execute_subcommand(scenario.config, subcommand)
  File "/home/iinuwa/.local/lib/python3.9/site-packages/molecule/command/base.py", line 149, in execute_subcommand
    return command(config).execute()
  File "/home/iinuwa/.local/lib/python3.9/site-packages/molecule/logger.py", line 188, in wrapper
    rt = func(*args, **kwargs)
  File "/home/iinuwa/.local/lib/python3.9/site-packages/molecule/command/login.py", line 101, in execute
    self._get_login(hostname)
  File "/home/iinuwa/.local/lib/python3.9/site-packages/molecule/command/login.py", line 146, in _get_login
    app.runtime.exec(cmd)
  File "/home/iinuwa/.local/lib/python3.9/site-packages/ansible_compat/runtime.py", line 138, in exec
    result = run_func(
  File "/usr/lib/python3.9/subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/env docker exec -e COLUMNS=106 -e LINES=54 -e TERM=bash -e TERM=xterm -ti instance bash'

I think that the problem is the type of args. I can reproduce with just this:

import subprocess

args = '/usr/bin/env docker exec -e COLUMNS=106 -e LINES=54 -e TERM=bash -e TERM=xterm -ti instance bash'

run_func = subprocess.run

result = run_func(args)
Traceback (most recent call last):
  File "/tmp/repro.py", line 7, in <module>
    result = run_func(
  File "/usr/lib/python3.9/subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/env docker exec -e COLUMNS=106 -e LINES=54 -e TERM=bash -e TERM=xterm -ti instance bash'

If I change args to a list, it works properly:

import subprocess

args = ['/usr/bin/env', 'docker', 'exec', '-e', 'COLUMNS=106', '-e', 'LINES=54', '-e', 'TERM=bash', '-e', 'TERM=xterm', '-ti', 'instance', 'bash']

run_func = subprocess.run

result = run_func(args)
[root@instance /]#

For some reason, when I try to patch this in ansible_compat/runtime.py:138, it just hangs:

+        args = args.split(' ')
        for _ in range(self.max_retries + 1 if retry else 1):
            result = run_func(
                args,
                universal_newlines=True,
                check=False,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                env=env or self.environ,
                cwd=cwd,
            )
# ...

I’ve created fix for this, adding .split(" ") and replacing ansible runtime with simple subprocess.run. It worked for my ssh connection, additional testing for different drivers is welcomed.

See #3468

FYI shlex.split() would be more robust for argument splitting.

Also in theory, you would have been able to keep the app.runtime.exec() and only needed to provide the tee=true parameter. Unfortunately, there is a bug in the subprocess_tee library, that causes output to only printed on line breaks, so the revert to normal subprocess is correct for now.

Downgrading to Molecule 3.5.2 works as expected

$ molecule --version
molecule 3.5.2 using python 3.9
    ansible:2.12.2
    delegated:3.5.2 from molecule
    ec2:0.4 from molecule_ec2
    vagrant:1.0.0 from molecule_vagrant

$ molecule --env-file molecule/common/molecule.env.yml  login --scenario-name vagrant-centos-7
INFO     Inventory /Users/isuftin/Development/CTek/automation/ansible/roles/ssl_filtering/molecule/vagrant-centos-7/../common/group_vars linked to /Users/isuftin/.cache/molecule/ssl_filtering/vagrant-centos-7/inventory/group_vars
INFO     Running vagrant-centos-7 > login
Last login: Tue Feb 15 19:19:35 2022 from 10.0.2.2

This system is built by the Bento project by Chef Software
More information can be found at https://github.com/chef/bento

Same issue here but with docker. Verified 3.5.2 is working indeed. Running the command worked fine too so it must be an issue with the subprocess call.