此 Play 安装python3
、pip3
、boto3
和botocore
,并尝试使用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"}
Run Code Online (Sandbox Code Playgroud)
它失败了,因为它说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 ~]
Run Code Online (Sandbox Code Playgroud)
这是安装的任务boto3
:
- name: Install boto3 and botocore with pip3 module
pip:
name:
- boto3
- botocore
executable: pip-3.7
Run Code Online (Sandbox Code Playgroud)
这是失败的任务:
- 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
Run Code Online (Sandbox Code Playgroud)
目标主机确实安装了两个版本的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
Run Code Online (Sandbox Code Playgroud)
我的配置文件如下所示:
[defaults]
private_key_file=/home/ec2-user/manual-builds/key.pem
ansible_python_interpreter=/usr/bin/python3
Run Code Online (Sandbox Code Playgroud)
这是一个错误吗?我看到近一年前有人问过一些类似的问题,但我没有看到解决方案 - 非常感谢您的帮助。
问题是我的剧本有两个任务,而 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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14944 次 |
最近记录: |