我有一个混合了连接的剧本:使用 AWS 动态清单的本地任务和远程任务。 python解释器在本地和远程系统上有不同的路径。
通过另一个问题python3 venv - 如何为混合连接的剧本同步ansible_python_interpreter:本地和目标系统我已经确定我应该使用ansible_python_interpreter_fallback配置2个python解释器路径来尝试。但我无法让他们工作。我试过了:
剧本:
---
- hosts: tag_group_web_servers
vars_files:
- group_vars/au
roles:
- autodeploy
vars:
ansible_python_interpreter_fallback:
- /Users/jd/projects/mgr2/ansible/bin/python3
- /usr/bin/python3
(忽略)
动态库存:
plugin: aws_ec2
regions:
- ap-southeast-2
- us-east-1
hostnames:
- ip-address
keyed_groups:
- prefix: "tag"
key: tags
- prefix: "group"
key: tags
- prefix: "security_groups"
key: 'security_groups|json_query("[].group_name")'
all:
hosts:
127.0.0.1:
ansible_connection: local
ansible_python_interpreter: "/Users/jd/projects/mgr2/ansible/bin/python3"
remote:
ansible_host: remote.host.ip
ansible_python_interpreter: /usr/bin/python3
ansible_python_interpreter_fallback:
- /Users/jd/projects/mgr2/ansible/bin/python3
- /usr/bin/python3
(忽略)
我很困惑这还能去哪里或者为什么它不起作用。 Ansible 版本在这里:
ansible [core 2.17.4]
config file = /Users/jd/projects/mgr2/ansible/ansible.cfg
configured module search path = ['/Users/jd/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /opt/homebrew/lib/python3.11/site-packages/ansible
ansible collection location = /Users/jd/.ansible/collections:/usr/share/ansible/collections
executable location = /opt/homebrew/bin/ansible
python version = 3.11.10 (main, Sep 7 2024, 01:03:31) [Clang 15.0.0 (clang-1500.3.9.4)] (/opt/homebrew/opt/[email protected]/bin/python3.11)
jinja version = 3.1.4
libyaml = True
查看
ansible --version
的输出,我注意到您没有使用 "/Users/jd/projects/mgr2/ansible/bin/python3"
。 brew install ansible 位于您的 $PATH 中。对于 virtualenv source /Users/jd/projects/mgr2/ansible/bin/activate
。
请注意,Ansible 在大多数平台上会自动发现 python 解释器。 文档:解释器发现