1

I'm trying to run molecule converge on a newly-created Molecule role (created by running molecule init role shahradr.srx_config --driver-name docker), but I'm getting the following error when running the converge step:

fatal: [instance]: FAILED! => {
    "ansible_facts": {},
    "changed": false,
    "failed_modules": {
        "ansible.legacy.setup": {
            "ansible_facts": {
                "discovered_interpreter_python": "/usr/bin/python3"
            },
            "failed": true,
            "module_stderr": "",
            "module_stdout": "",
            "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
            "rc": 0
        }
    },
    "msg": "The following modules failed to execute: ansible.legacy.setup\n"
}

I've tried different container images, but they all give me the same error. The ansible.legacy.setup task seems to be the culprit, judging from the value in msg, but it looks like it was able to find the Python interpreter, the return code is 0, and there are no errors in stderr/stdout. I'm wondering if anyone has ever seen anything similar before?

Here are some of the relevant files—let me know what you all think!

molecule.yml

---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: instance
    image: python # also tried quay.io/quay/ubuntu and quay.io/centos/centos:stream8, but no dice

provisioner:
  name: ansible
  env:
    ANSIBLE_VERBOSITY: 4

verifier:
  name: ansible

converge.yml

---
- name: Converge
  hosts: all
  tasks:
    - name: "Include shahradr.srx_config"
      include_role:
        name: "shahradr.srx_config"

molecule converge output

PLAYBOOK: converge.yml *********************************************************
Positional arguments: /workspaces/playbook-srx/molecule/default/converge.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
skip_tags: ('notest', 'molecule-notest')
inventory: ('/home/vscode/.cache/molecule/playbook-srx/default/inventory',)
forks: 50
1 plays in /workspaces/playbook-srx/molecule/default/converge.yml

PLAY [Converge] ****************************************************************

TASK [Gathering Facts] *********************************************************
task path: /workspaces/playbook-srx/molecule/default/converge.yml:2
fatal: [instance]: FAILED! => {
    "ansible_facts": {},
    "changed": false,
    "failed_modules": {
        "ansible.legacy.setup": {
            "ansible_facts": {
                "discovered_interpreter_python": "/usr/bin/python3"
            },
            "failed": true,
            "module_stderr": "",
            "module_stdout": "",
            "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
            "rc": 0
        }
    },
    "msg": "The following modules failed to execute: ansible.legacy.setup\n"
}
Loading collection community.docker from /home/vscode/.cache/ansible-compat/874d52/collections/ansible_collections/community/docker
<instance> ESTABLISH DOCKER CONNECTION FOR USER: root
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', "/bin/sh -c 'echo ~ && sleep 0'"]
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', '/bin/sh -c \'( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1671693905.9801428-31004-54819707870645 `" && echo ansible-tmp-1671693905.9801428-31004-54819707870645="` echo /root/.ansible/tmp/ansible-tmp-1671693905.9801428-31004-54819707870645 `" ) && sleep 0\'']
<instance> Attempting python interpreter discovery
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', '/bin/sh -c \'echo PLATFORM; uname; echo FOUND; command -v \'"\'"\'python3.11\'"\'"\'; command -v \'"\'"\'python3.10\'"\'"\'; command -v \'"\'"\'python3.9\'"\'"\'; command -v \'"\'"\'python3.8\'"\'"\'; command -v \'"\'"\'python3.7\'"\'"\'; command -v \'"\'"\'python3.6\'"\'"\'; command -v \'"\'"\'python3.5\'"\'"\'; command -v \'"\'"\'/usr/bin/python3\'"\'"\'; command -v \'"\'"\'/usr/libexec/platform-python\'"\'"\'; command -v \'"\'"\'python2.7\'"\'"\'; command -v \'"\'"\'/usr/bin/python\'"\'"\'; command -v \'"\'"\'python\'"\'"\'; echo ENDFOUND && sleep 0\'']
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', "/bin/sh -c '/usr/local/bin/python3.11 && sleep 0'"]
Using module file /usr/local/python/3.10.9/lib/python3.10/site-packages/ansible/modules/setup.py
<instance> PUT /home/vscode/.ansible/tmp/ansible-local-30997q9s35pno/tmpkw2qa3kw TO /root/.ansible/tmp/ansible-tmp-1671693905.9801428-31004-54819707870645/AnsiballZ_setup.py
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', "/bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1671693905.9801428-31004-54819707870645/ /root/.ansible/tmp/ansible-tmp-1671693905.9801428-31004-54819707870645/AnsiballZ_setup.py && sleep 0'"]
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', "/bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1671693905.9801428-31004-54819707870645/AnsiballZ_setup.py && sleep 0'"]
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', "/bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1671693905.9801428-31004-54819707870645/ > /dev/null 2>&1 && sleep 0'"]

PLAY RECAP *********************************************************************
instance                   : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

ansible --version output

ansible [core 2.14.1]
  config file = None
  configured module search path = ['/home/vscode/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/python/3.10.9/lib/python3.10/site-packages/ansible
  ansible collection location = /home/vscode/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/python/current/bin/ansible
  python version = 3.10.9 (main, Dec 18 2022, 21:59:57) [GCC 10.2.1 20210110] (/usr/local/python/3.10.9/bin/python3.10)
  jinja version = 3.1.2
  libyaml = True

molecule --version output

molecule 4.0.4 using python 3.10 
    ansible:2.14.1
    delegated:4.0.4 from molecule
    docker:2.1.0 from molecule_docker requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0

Running with an older version of Ansible

ansible --version output

ansible [core 2.12.0]
  config file = None
  configured module search path = ['/home/vscode/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/python/3.8.16/lib/python3.8/site-packages/ansible
  ansible collection location = /home/vscode/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/python/current/bin/ansible
  python version = 3.8.16 (default, Dec 22 2022, 09:25:11) [GCC 10.2.1 20210110]
  jinja version = 3.1.2
  libyaml = True

molecule --version output

molecule 4.0.4 using python 3.8 
    ansible:2.12.0
    delegated:4.0.4 from molecule
    docker:2.1.0 from molecule_docker requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0

molecule converge output

PLAY [Converge] ****************************************************************

TASK [Gathering Facts] *********************************************************
task path: /workspaces/playbook-srx/molecule/default/converge.yml:2
Loading collection community.docker from /home/vscode/.cache/ansible-compat/874d52/collections/ansible_collections/community/docker
<instance> ESTABLISH DOCKER CONNECTION FOR USER: root
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', "/bin/sh -c 'echo ~ && sleep 0'"]
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', '/bin/sh -c \'( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1671797674.6429565-10250-103016948866633 `" && echo ansible-tmp-1671797674.6429565-10250-103016948866633="` echo /root/.ansible/tmp/ansible-tmp-1671797674.6429565-10250-103016948866633 `" ) && sleep 0\'']
<instance> Attempting python interpreter discovery
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', '/bin/sh -c \'echo PLATFORM; uname; echo FOUND; command -v \'"\'"\'python3.10\'"\'"\'; command -v \'"\'"\'python3.9\'"\'"\'; command -v \'"\'"\'python3.8\'"\'"\'; command -v \'"\'"\'python3.7\'"\'"\'; command -v \'"\'"\'python3.6\'"\'"\'; command -v \'"\'"\'python3.5\'"\'"\'; command -v \'"\'"\'/usr/bin/python3\'"\'"\'; command -v \'"\'"\'/usr/libexec/platform-python\'"\'"\'; command -v \'"\'"\'python2.7\'"\'"\'; command -v \'"\'"\'python2.6\'"\'"\'; command -v \'"\'"\'/usr/bin/python\'"\'"\'; command -v \'"\'"\'python\'"\'"\'; echo ENDFOUND && sleep 0\'']
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', "/bin/sh -c '/usr/bin/python3 && sleep 0'"]
Using module file /usr/local/python/3.8.16/lib/python3.8/site-packages/ansible/modules/setup.py
<instance> PUT /home/vscode/.ansible/tmp/ansible-local-10226yeg_lu0l/tmpg3_giq0y TO /root/.ansible/tmp/ansible-tmp-1671797674.6429565-10250-103016948866633/AnsiballZ_setup.py
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', "/bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1671797674.6429565-10250-103016948866633/ /root/.ansible/tmp/ansible-tmp-1671797674.6429565-10250-103016948866633/AnsiballZ_setup.py && sleep 0'"]
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', "/bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1671797674.6429565-10250-103016948866633/AnsiballZ_setup.py && sleep 0'"]
<instance> EXEC ['/usr/bin/docker', b'exec', b'-i', 'instance', '/bin/sh', '-c', "/bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1671797674.6429565-10250-103016948866633/ > /dev/null 2>&1 && sleep 0'"]
fatal: [instance]: FAILED! => {
    "ansible_facts": {},
    "changed": false,
    "failed_modules": {
        "ansible.legacy.setup": {
            "ansible_facts": {
                "discovered_interpreter_python": "/usr/bin/python"
            },
            "failed": true,
            "module_stderr": "",
            "module_stdout": "",
            "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
            "rc": 0
        }
    },
    "msg": "The following modules failed to execute: ansible.legacy.setup\n"
}
ShahradR
  • 11
  • 4
  • Please [edit] your question and add the output of `ansible --version` and `molecule --version` – Zeitounator Dec 22 '22 at 08:34
  • For sure—I just updated the post now! – ShahradR Dec 22 '22 at 08:40
  • It could be that your Ansible version is too new for Molecule. Would it be possible to downgrade Ansible? – Kevin C Dec 22 '22 at 10:25
  • [I can't reproduce your issue](https://gist.github.com/zeitounator/f657b81019f7efe9a42b60644b0fe4af). I also tested with a non pre-built image and get the same result (i.e. facts are gathered correctly). – Zeitounator Dec 22 '22 at 17:23
  • @KevinC that was a good idea, but unfortunately it gives the same results. I've updated the question with the `--version` and `molecule converge` outputs. – ShahradR Dec 23 '22 at 12:34
  • @Zeitounator thank you so much for trying that out! At least now we can rule out configuration issues, and it probably points to something weird with my setup. I am running this in a development container—I'm wondering now if that could be the culprit? I'll play with my setup a bit, see if it works outside the devcontainer, maybe? – ShahradR Dec 23 '22 at 12:40

1 Answers1

0

I think I might have figured it out—it looks like the issue was caused by my devcontainer configuration. I had enabled both the docker-in-docker and docker-from-docker features at the same time, which resulted in the issue listed above.

If I disable either feature, then the molecule converge command completes successfully, and I don't get the ansible.legacy.setup error detailed in this question.

.devcontainer/devcontainer.json

{
  "name": "Debian",
  "runArgs": ["--init"],
  "build": {
    "dockerfile": "Dockerfile",
    "args": { "VARIANT": "bullseye" }
  },
  "settings": {},
  "extensions": [],
  "remoteUser": "vscode",
  "features": {
    // Having both the docker-in-docker and docker-from-docker features enabled
    // causes the ansible.legacy.setup error detailed in this question.
    "ghcr.io/devcontainers/features/docker-in-docker:1": {
      "version": "latest"
    },
    "ghcr.io/devcontainers/features/docker-from-docker:1": {
      "version": "latest"
    },
    "ghcr.io/devcontainers/features/node:1": {
      "version": "16"
    },
    "ghcr.io/devcontainers/features/python:1": {
      "version": "3.8"
    }
  },
  "postCreateCommand": ["./.devcontainer/post-create.sh"]
}

molecule converge output with both the docker-in-docker and docker-from-docker features enabled

TASK [Gathering Facts] *********************************************************
fatal: [instance]: FAILED! => {
    "ansible_facts": {},
    "changed": false,
    "failed_modules": {
        "ansible.legacy.setup": {
            "ansible_facts": {
                "discovered_interpreter_python": "/usr/bin/python"
            },
            "failed": true,
            "module_stderr": "",
            "module_stdout": "",
            "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
            "rc": 0
        }
    },
    "msg": "The following modules failed to execute: ansible.legacy.setup\n"
}

molecule converge output with only the docker-in-docker feature enabled

TASK [Gathering Facts] *********************************************************
ok: [instance]

molecule converge output with only the docker-from-docker feature enabled

TASK [Gathering Facts] *********************************************************
ok: [instance]
ShahradR
  • 11
  • 4