【问题标题】:Ansible not reading credentials from ~/.aws/credentialsAnsible 未从 ~/.aws/credentials 读取凭据
【发布时间】:2017-02-10 14:25:08
【问题描述】:

我正在使用 dynamic inventory 运行 ansible。当aws cli 使用 aws configure 命令设置时,具有动态清单的 ansible 命令运行正常。但是我想有多个配置文件供动态库存使用,所以我在~/.aws/credentials 中添加了配置文件

[personal]
aws_access_key_id = XXXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXXXX

[default]
aws_access_key_id = XXXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXXXX

ansible 未获取这些凭据并在运行 ./ec2.py --list 时出现错误:

Looks like AWS is down again:
EC2ResponseError: 401 Unauthorized
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>AuthFailure</Code><Message>Authorization header or parameters are not formatted correctly.</Message></Error></Errors><RequestID>349d5311-54db-4e79-9bbc-2d60b9f15da5</RequestID></Response>

【问题讨论】:

    标签: python amazon-web-services ansible aws-cli


    【解决方案1】:

    我也遇到过这个问题,最终解决了;问题是我机器上的时钟偏移了几分钟。正确设置时间可以解决问题。

    在此过程中,我了解到 aws cli 使用 boto3,而 ec2.py 使用 boto。似乎 boto3 在身份验证方面的工作方式略有不同,因为就像 @drishti 一样,即使 ec2.py 没有,CLI 也为我工作。

    【讨论】:

      【解决方案2】:

      您是否尝试将 --profile PROFILE 开关添加到 ec2.py,如下所示。

      ./ec2.py --list --profile personal
      

      【讨论】:

      • 它给出错误 - usage: hosts [-h] [--list] [--host HOST] [--refresh-cache] hosts: error: unrecognized arguments: --profile personal
      • 您能否确保您拥有最新的 ec2.py 文件。我有一个 --profile 选项./ec2.py --help usage: ec2.py [-h] [--list] [--host HOST] [--refresh-cache] [--profile BOTO_PROFILE]
      • 粘贴ec2.py link
      • 是的,你是对的。现在我有最新的 ec2.py 但它仍然给出错误 - ERROR: "Authentication error retrieving ec2 inventory. - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment vars found but may not be correct - Boto configs found at '~/.boto, ~/.aws/credentials', but the credentials contained may not be correct", while: getting EC2 instances
      【解决方案3】:

      在@uptime365 的回答之后,这很可能不是 Ansible/ec2.py 问题。这是我的故障排除步骤:

      您可以将awscli 与这些凭据一起使用吗?

      aws ec2 describe-instances --page-size 5
      aws ec2 describe-instances --page-size 5 --profile personal
      

      您可以使用 awscli 并手动包含凭据吗?

      请注意,无需使用 profile,因为您正在指定键。

      AWS_ACCESS_KEY_ID="AKIA.." AWS_SECRET_ACCESS_KEY=".."  aws ec2 describe-instances --page-size 5
      

      如果它抱怨该地区,请添加AWS_DEFAULT_REGION="us-east-1" 或您选择的地区。

      这些都不起作用

      您的访问密钥或密钥有问题。每个字有多少个?密钥应为 20 个字符,全部为大写字母和数字。秘密是 40 个字符,大写/小写/数字/标点符号。

      【讨论】:

      • 它与aws ec2 describe-instances --page-size 5 --profile personal 一起工作,但是当我运行./ec2.py --list --profile personal 时,它给出了错误-ERROR: "Authentication error retrieving ec2 inventory. - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment vars found but may not be correct - Boto configs found at '~/.boto, ~/.aws/credentials', but the credentials contained may not be correct", while: getting EC2 instances
      • 在 ec2.py 之前添加配置文件,如下所示:AWS_PROFILE=personal ./ec2.py
      • 整个 ec2.py 粘贴到gist 中。有一些你没有分享的东西导致这个失败。也可能是屏幕的副本,显示文件、运行方式、用户名、主机等。
      • aws-cli 使用凭据运行良好。只是 ansible 动态库存没有获取凭据。
      猜你喜欢
      • 2019-02-23
      • 2020-12-29
      • 2018-09-23
      • 2018-07-08
      • 2017-07-15
      • 1970-01-01
      • 2021-11-13
      • 1970-01-01
      • 2013-10-15
      相关资源
      最近更新 更多