gpt4 book ai didi

Ansible aws_s3 模块失败时说缺少 Boto3

转载 作者:行者123 更新时间:2023-12-03 20:28:41 25 4
gpt4 key购买 nike

本剧安装python3 , pip3 , boto3botocore ,并尝试使用 aws_s3 模块下载文件:

TASK [run yum update -y using yum module] 
**********************************************************************
ok: [ip-10-200-2-137.us-west-2.compute.internal]

TASK [Install python3 and pip3] *************************************************************************************************
changed: [ip-10-200-2-137.us-west-2.compute.internal]

TASK [Install boto3 and botocore with pip3 module] ******************************************************************************
changed: [ip-10-200-2-137.us-west-2.compute.internal]

TASK [Create a directory if it does not exist using file module] ****************************************************************
changed: [ip-10-200-2-137.us-west-2.compute.internal]

TASK [downlod file from s3 with aws_s3 module] **********************************************************************************
fatal: [ip-10-200-2-137.us-west-2.compute.internal]: FAILED! =>
{"changed": false, "msg": "Python modules \"botocore\" or \"boto3\"
are missing, please install both"}
它失败了,因为它说 boto3不见了,但实际上不是:
从目标主机可以看到 boto3已安装:
[ec2-user@ip-10-200-2-137 ~]$ pip3 freeze
boto3==1.9.120
botocore==1.12.120
docutils==0.14
jmespath==0.9.4
python-dateutil==2.8.0
s3transfer==0.2.0
six==1.12.0
urllib3==1.24.1
[ec2-user@ip-10-200-2-137 ~]
这是安装 boto3 的任务:
- name: Install boto3 and botocore with pip3 module
pip:
name:
- boto3
- botocore
executable: pip-3.7
这是失败的任务:
- name: downlod file from s3 with aws_s3 module 
aws_s3:
bucket: mybucket
object: mybucket/jre-8u201-linux-x64.tar.gz
dest: /home/ec2-user/updater/jre-8u201-linux-x64.tar.gz
mode: get
目标主机确实安装了两个版本的 Python:
[ec2-user@ip-10-200-2-157 ~]$ which python
/usr/bin/python
[ec2-user@ip-10-200-2-157 ~]$ which python3
/usr/bin/python3
我的配置文件如下所示:
[defaults]
private_key_file=/home/ec2-user/manual-builds/key.pem
ansible_python_interpreter=/usr/bin/python3
这是一个错误吗?我看到一些类似的问题被问到近一年前,但我没有看到任何解决方案 - 非常感谢您的帮助。

最佳答案

问题是我的剧本有两个任务,而 Ansible 使用 python2 解释器来处理第一个和第二个。第二个任务需要 python3 解释器才能工作,所以我必须在任务级别指定它:

- name: downlod file from s3 with aws_s3 module
vars:
ansible_python_interpreter: /usr/bin/python3
aws_s3:
bucket: launch-data
object: jre-8u201-linux-x64.tar.gz
dest: /home/ec2-user/updater/jre-8u201-linux-x64.tar.gz
mode: get

关于Ansible aws_s3 模块失败时说缺少 Boto3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55308062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com