如何在Amazon Linux 2上使用ansible修复“导入所需Python库(botocore或boto3)失败”?
我通常可以通过指定如何在Amazon Linux 2上使用ansible修复“导入所需Python库(botocore或boto3)失败”?,python,python-3.x,linux,ansible,Python,Python 3.x,Linux,Ansible,我通常可以通过指定ansible\u python\u解释器:/usr/bin/python3 尽管在amazonlinux2(cloud9)中使用了ansible\u python\u解释器:/usr/bin/python3,但在amazonlinux2上运行以下playbook时仍然会出错 - hosts: localhost connection: local gather_facts: "{{ variable_gather_facts | default('false
ansible\u python\u解释器:/usr/bin/python3
尽管在amazonlinux2(cloud9)中使用了ansible\u python\u解释器:/usr/bin/python3
,但在amazonlinux2上运行以下playbook时仍然会出错
- hosts: localhost
connection: local
gather_facts: "{{ variable_gather_facts | default('false') }}"
become: true
any_errors_fatal: true
tasks:
- name: "Create a role and attach a managed policy called 'aws-ec2-spot-fleet-tagging-role'"
community.aws.iam_role:
name: aws-ec2-spot-fleet-tagging-role
assume_role_policy_document: "{{ lookup('file','policy.json') }}"
managed_policies:
- arn:aws:iam::aws:policy/service-role/AmazonEC2SpotFleetTaggingRole
vars:
ansible_python_interpreter: /usr/bin/python3
我已使用此方法安装了这些软件包,因此不清楚发生上述错误的原因:
python3 -m pip install --user --upgrade pip
python3 -m pip install ansible boto3 botocore
我还可以验证在运行python时是否可以导入这两个库
此外,这里还有一些更有用的信息:
ansible --version
ansible 2.10.7
config file = None
configured module search path = ['/home/ec2-user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/ec2-user/.local/lib/python3.7/site-packages/ansible
executable location = /home/ec2-user/.local/bin/ansible
python version = 3.7.9 (default, Feb 18 2021, 03:10:35) [GCC 7.3.1 20180712 (Red Hat 7.3.1-12)]
该软件包需要安装在目标计算机上。这可以通过添加以下任务来解决(oneliner,因为在注释中…):
{name:“确保安装了boto”,pip:{name:['boto3','bobocore']}
我已经这样做了,但它不起作用。在您的问题中,我看到您试图使用交互式会话路径中的python3
二进制文件在本地主机上手动安装libs。我看不到有人试图在ip-172-31-28-167.ap-southeast-2.compute.internal
上安装这些文件,或者确保libs确实安装在那里(从错误消息来看,情况显然不是这样)。
ansible --version
ansible 2.10.7
config file = None
configured module search path = ['/home/ec2-user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/ec2-user/.local/lib/python3.7/site-packages/ansible
executable location = /home/ec2-user/.local/bin/ansible
python version = 3.7.9 (default, Feb 18 2021, 03:10:35) [GCC 7.3.1 20180712 (Red Hat 7.3.1-12)]