我试图在新创建的分子角色上运行molecule converge
(通过运行molecule init role shahradr.srx_config --driver-name docker
创建),但在运行收敛步骤时,我得到以下错误:
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 FAILUREnSee stdout/stderr for the exact error",
"rc": 0
}
},
"msg": "The following modules failed to execute: ansible.legacy.setupn"
}
我尝试过不同的容器图像,但它们都给我相同的错误。ansible.legacy.setup任务似乎是罪魁祸首,从msg
中的值判断,但看起来它能够找到Python解释器,返回代码为0,并且stderr/stdout中没有错误。我想知道有没有人以前见过类似的情况?
这里是一些相关的文件,让我知道你的想法!
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
输出
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 FAILUREnSee stdout/stderr for the exact error",
"rc": 0
}
},
"msg": "The following modules failed to execute: ansible.legacy.setupn"
}
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
输出
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
输出
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
使用旧版本的Ansible
ansible --version
输出
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
输出
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
输出
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 FAILUREnSee stdout/stderr for the exact error",
"rc": 0
}
},
"msg": "The following modules failed to execute: ansible.legacy.setupn"
}
我想我可能已经弄清楚了——看起来这个问题是由我的devcontainer配置引起的。我同时启用了docker-in-docker和docker-from-docker特性,这导致了上面列出的问题。
如果我禁用任何一个功能,那么molecule converge
命令成功完成,并且我没有得到这个问题中详细的ansible.legacy.setup
错误。
.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"]
}
启用docker-in-docker和docker-from-docker特性的molecule converge
输出
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 FAILUREnSee stdout/stderr for the exact error",
"rc": 0
}
},
"msg": "The following modules failed to execute: ansible.legacy.setupn"
}
仅启用docker-in-docker特性的molecule converge
输出
TASK [Gathering Facts] *********************************************************
ok: [instance]
仅启用docker-from-docker特性的molecule converge
输出
TASK [Gathering Facts] *********************************************************
ok: [instance]