# Ansible dynamic inventory: Authentication error retrieving ec2 inventory

**URL:** <https://forum.ansible.com/t/ansible-dynamic-inventory-authentication-error-retrieving-ec2-inventory/23808>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [February 24, 2017, 4:28pm UTC](https://forum.ansible.com/t/ansible-dynamic-inventory-authentication-error-retrieving-ec2-inventory/23808 "2017-02-24T16:28:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prithula\_Mukherjee](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@Prithula\_Mukherjee](https://forum.ansible.com/u/Prithula_Mukherjee)\
**Post date:** [February 24, 2017, 4:28pm UTC](https://forum.ansible.com/t/ansible-dynamic-inventory-authentication-error-retrieving-ec2-inventory/23808/1 "2017-02-24T16:28:06Z")

</div>

I am using Ansible’s Dynamic Inventory feature to connect to the ec2 instances in AWS account using below:

AWS\_PROFILE=personal ansible-playbook cifarm.yml -C

I have copied the [https://raw.github.com/ansible/ansible/devel/contrib/inventory/ec2.py](https://raw.github.com/ansible/ansible/devel/contrib/inventory/ec2.py) into and [https://raw.github.com/ansible/ansible/devel/contrib/inventory/ec2.ini](https://raw.github.com/ansible/ansible/devel/contrib/inventory/ec2.ini) file under inventory directory.

On running AWS\_PROFILE=personal ansible-playbook cifarm.yml -C, it throws below error:

**Output** :

_ERROR: Inventory script (inventory/ec2.py) had an execution error: 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_

I am running the playbook from a MAC OS. Please note that I am able to run below successfully:

_aws ec2 describe-instances --page-size 5 --profile personal_

This proves that the credentials are correct and also I have exported the AWS\_ACCESS\_KEY\_ID and AWS\_SECRET\_ACCESS\_KEY. I tried to execute the inventory/ec2.py file as below:

./ec2.py --list

And it comes back with the same error. I saw a post where it was suggested to update the time on the machine, I am running the playbook. So I ran ntpdate -u

But the issue still persists. I have no idea what is the reason. Any help/suggestions is much appreciated.
