【发布时间】:2019-09-29 16:20:10
【问题描述】:
我正在尝试使用 aws cli 运行以下任务,因为 aws_s3 模块将所有存储桶键都展平。但是,我不断收到aws: not found 错误。aws cli 已正确安装,因为从主机运行完全相同的命令,工作正常。
我的任务:
- name: Try list
shell: aws s3 ls "{{ s3_bucket }}"
完整的错误:
fatal: [cassandra-node-1]: FAILED! => {
"changed": true,
"cmd": "aws s3 ls \"cassandra-snapshotter-test2\"",
"delta": "0:00:00.002900",
"end": "2019-05-12 13:48:25.705324",
"invocation": {
"module_args": {
"_raw_params": "aws s3 ls \"cassandra-snapshotter-test2\"",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"msg": "non-zero return code",
"rc": 127,
"start": "2019-05-12 13:48:25.702424",
"stderr": "/bin/sh: 1: aws: not found",
"stderr_lines": [
"/bin/sh: 1: aws: not found"
],
"stdout": "",
"stdout_lines": []
}
为什么我不能从 Ansible 任务运行 aws cli?
【问题讨论】:
-
很难确定问题的根源,但到目前为止,我想到了两个可能的问题:1. 这个任务是在
hosts: localhost上执行的吗(因为我假设你有本地安装的 aws cli)。 2. aws cli 是在系统范围内安装的,还是仅为您的用户安装(并添加到 $PATH),并且由于某种原因,ansible 以不同的用户身份启动并清除了环境变量。 -
另外,虽然这不是您所要求的,但执行您想做的事情的“可靠方式”是通过
aws_s3: mode=list bucket={{s3_bucket}} -
@MatthewLDaniel 我在帖子中提到,使用
aws_s3对我不起作用,因为这让我所有的键都是平的,而shell: aws s3 ls只提供顶级文件夹。 -
@PiotrWicijowski 我没有在本地主机上运行。 aws cli 在 PATH 上,但显然这是一个问题:github.com/ansible/ansible/issues/25147
标签: amazon-web-services ansible sh aws-cli