# Dynamic Inventory - AWS EC2

**URL:** <https://forum.ansible.com/t/dynamic-inventory-aws-ec2/2155>\
**Category:** Get Help\
**Tags:** collections, aws\
**Created:** [November 5, 2023, 9:27pm UTC](https://forum.ansible.com/t/dynamic-inventory-aws-ec2/2155 "2023-11-05T21:27:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jalsaman](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jalsaman/32/1187_2.png) [@jalsaman](https://forum.ansible.com/u/jalsaman)\
**Post date:** [November 5, 2023, 9:27pm UTC](https://forum.ansible.com/t/dynamic-inventory-aws-ec2/2155/1 "2023-11-05T21:27:29Z")

</div>

Hi All,

Here is my lab setup  
ansible-master  
node1  
node2  
All are on AWS (EC2 Instances)

I attached IAM Role (Administrator) to my Ansible-master

**aws\_ec2.yaml**

plugin: aws\_ec2  
#aws\_profile: default  
regions:

- eu-central-1

Contents of ansible.cfg  
enable\_plugins = host\_list, virtualbox, yaml, constructed, aws\_ec2, script, ini, auto, toml

Still Ansible-inventory command doesn’t retreive my node1 and node2.

Can someone help me in this.

-jalsaman

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [November 6, 2023, 2:03pm UTC](https://forum.ansible.com/t/dynamic-inventory-aws-ec2/2155/2 "2023-11-06T14:03:03Z")

</div>

Do you have boto3 and botocore installed on ansible-master?

You could check you have the profile attached with the `aws` CLI by running `aws sts get-caller-identity` on ansible-master, and verify you have a permissions attached to the profile with `aws ec2 describe-instances`

If the aws\_ec2 inventory plugin had an issue you should see a warning, for example  
“[WARNING]: \* Failed to parse aws\_ec2.yml with auto plugin: Failed to import the required Python library (botocore and boto3)…”  
or  
“[WARNING]: \* Failed to parse aws\_ec2.yml with auto plugin: Failed to describe instances: An error occurred (InvalidClientTokenId) when calling the AssumeRole operation: The security token included in the  
request is invalid.”

Also just to note, aws\_ec2 doesn’t need to be configured (the `auto` plugin will parse it).

---

<div class="post-metadata">

**Author:** ![jalsaman](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jalsaman/32/1187_2.png) [@jalsaman](https://forum.ansible.com/u/jalsaman)\
**Post date:** [November 6, 2023, 8:40pm UTC](https://forum.ansible.com/t/dynamic-inventory-aws-ec2/2155/3 "2023-11-06T20:40:04Z")

</div>

Hi Shertel,

Thanks for reaching out.

I tried

aws sts get-caller-identity

“UserId”: “AROAXGJWXEQ4XFI6D6IEG:i-0fb418d79eda012548”,  
“Account”: “49457287212458”,  
“Arn”: “arn:aws:sts::49457287212345:assumed-role/aws-ec2-ansible/i-0fb418d79eda012548”

ubuntu@ip-172-31-17-69:~/ansible$ ansible-inventory -i aws\_ec2.yaml --list  
[WARNING]: Collection amazon.aws does not support Ansible version 2.10.8  
[WARNING]: \* Failed to parse /home/ubuntu/ansible/aws\_ec2.yaml with yaml plugin: Plugin configuration YAML file, not YAML  
inventory  
[WARNING]: \* Failed to parse /home/ubuntu/ansible/aws\_ec2.yaml with constructed plugin: Incorrect plugin name in file:  
aws\_ec2  
[WARNING]: \* Failed to parse /home/ubuntu/ansible/aws\_ec2.yaml with  
ansible\_collections.amazon.aws.plugins.inventory.aws\_ec2 plugin: ‘super’ object has no attribute ‘get\_options’  
[WARNING]: \* Failed to parse /home/ubuntu/ansible/aws\_ec2.yaml with ini plugin: Invalid host pattern ‘plugin:’ supplied,  
ending in ‘:’ is not allowed, this character is reserved to provide a port.  
[WARNING]: \* Failed to parse /home/ubuntu/ansible/aws\_ec2.yaml with auto plugin: ‘super’ object has no attribute  
‘get\_options’  
[WARNING]: Unable to parse /home/ubuntu/ansible/aws\_ec2.yaml as an inventory source  
[WARNING]: No inventory was parsed, only implicit localhost is available  
{  
“\_meta”: {  
“hostvars”: {}  
},  
“all”: {  
“children”: [  
“ungrouped”  
]  
}  
}  
ubuntu@ip-172-31-17-69:~/ansible$ aws ec2 describe-instances

An error occurred (AuthFailure) when calling the DescribeInstances operation: AWS was not able to validate the provided access credentials  
ubuntu@ip-172-31-17-69:~/ansible$

I tried AWS configure and everything is just blank

Regards,  
jalsaman

 ![Screenshot 2023-11-06 at 21.38.35.png](https://us1.discourse-cdn.com/ansible/original/2X/8/8a3edb72fea2bfd19687aeea4a0ea2990c5e47ef.png)

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [November 6, 2023, 11:18pm UTC](https://forum.ansible.com/t/dynamic-inventory-aws-ec2/2155/4 "2023-11-06T23:18:14Z")

</div>

> [WARNING]: \* Failed to parse /home/ubuntu/ansible/aws\_ec2.yaml with  
> ansible\_collections.amazon.aws.plugins.inventory.aws\_ec2 plugin: ‘super’ object has no attribute ‘get\_options’

amazon.aws 6.4.0 requires ansible-core \>=2.12.0, the plugin will not work with older versions

The instance profile needs to have permission for ec2:DescribeInstances. If you create an IAM role and attach a policy that allows it, you can add it to the instance profile ([AddRoleToInstanceProfile - AWS Identity and Access Management](https://docs.aws.amazon.com/IAM/latest/APIReference/API_AddRoleToInstanceProfile.html)). Or if you already have an IAM role associated with the instance profile, you may just need to adjust the policy ([Testing IAM policies with the IAM policy simulator - AWS Identity and Access Management](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_testing-policies.html)).

Speaking of `aws configure`, I guess it doesn’t show metadata, you could get temporary credentials this way though [IAM roles for Amazon EC2 - Amazon Elastic Compute Cloud](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#instance-metadata-security-credentials).
