首页 > 解决方案 > 错误是:botocore.exceptions.NoCredentialsError: Unable to locate credential

问题描述

嗨,我无法解决这些问题,我得到了这些,我的 ansible 代码无法找到凭据

可靠的代码

---
 - name: main yaml file
   remote_user: ec2-user
   become: yes
   hosts: localhost
   roles:
      - s3

角色:

- name: basic upload
  s3_sync:
   bucket: s3uploadlocust
   file_root: /home/ec2-user
   include: "*.csv"
   exclude: "*.txt,.*"
   permission: public-read
   file_change_strategy: force
   region: us-east-1

这是我的环境工具版本:

Name: boto3
Version: 1.12.2
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: UNKNOWN
License: Apache License 2.0
Location: /usr/local/lib/python2.7/site-packages
Requires: s3transfer, jmespath, botocore

Name: ansible
Version: 2.9.5
Summary: Radically simple IT automation
Home-page: https://ansible.com/
Author: Ansible, Inc.
Author-email: info@ansible.com
License: GPLv3+
Location: /usr/local/lib/python2.7/site-packages
Requires: jinja2, PyYAML, cryptography

Python 2.7.16

标签: ansibleboto3boto

解决方案


根据模块文档,您可以再提供 2 个参数:aws_access_keyaws_secret_key. 如果未设置AWS_ACCESS_KEY_ID,则使用AWS_ACCESS_KEYEC2_ACCESS_KEY环境变量的值aws_access_key。和AWS_SECRET_ACCESS_KEY, AWS_SECRET_KEY, 或EC2_SECRET_KEY环境变量用于aws_secret_key.


推荐阅读