# Issues setting up dynamic inventory in my AWS environment

**URL:** <https://forum.ansible.com/t/issues-setting-up-dynamic-inventory-in-my-aws-environment/10230>\
**Category:** Get Help\
**Tags:** aws, galaxy-ng\
**Created:** [October 12, 2024, 6:34pm UTC](https://forum.ansible.com/t/issues-setting-up-dynamic-inventory-in-my-aws-environment/10230 "2024-10-12T18:34:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arreyetta\_Bawak\_Augu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/arreyetta_bawak_augu/32/5130_2.png) [@Arreyetta\_Bawak\_Augu](https://forum.ansible.com/u/Arreyetta_Bawak_Augu)\
**Post date:** [October 12, 2024, 6:34pm UTC](https://forum.ansible.com/t/issues-setting-up-dynamic-inventory-in-my-aws-environment/10230/1 "2024-10-12T18:34:29Z")

</div>

I have been on a project to set-up a dynamic inventory in my AWS environment since the static inventory is not going to be useful.  
I have tried severally based by :

- Installing the prerequisites as the Ansible documentation says (pip3, boto3,boto, ansible-galaxy collection)
- Installed Ansible
- updated the ansible.cfg file, at the level of [inventory] with enable\_plugins = aws\_ec2
- Created the aws\_ec2.yml file updated the [defaults] section with my inventory file pointing at the aws\_ec2 file and including my key pairs to my worker nodes.
- Tried to ping the server worker nodes from the control but good error saying "parse aws\_ec2.yml can not be used as an inventory. I have do every magic but to no avail.

So I wish to know if you could be of help cause I wasn’t thinking maybe the Ansible package has an issue.

Thank you

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [October 12, 2024, 11:07pm UTC](https://forum.ansible.com/t/issues-setting-up-dynamic-inventory-in-my-aws-environment/10230/2 "2024-10-12T23:07:59Z")

</div>

I have been using Ansible’s AWS Dynamic Inventory for years without issue.

You’ll have to post at least your inventory file for anyone to have a chance to help you … and any command/playbook you are running with the associated error(s) - I recommend using `-vvv` to get verbose output

---

<div class="post-metadata">

**Author:** ![Arreyetta\_Bawak\_Augu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/arreyetta_bawak_augu/32/5130_2.png) [@Arreyetta\_Bawak\_Augu](https://forum.ansible.com/u/Arreyetta_Bawak_Augu)\
**Post date:** [October 13, 2024, 10:54am UTC](https://forum.ansible.com/t/issues-setting-up-dynamic-inventory-in-my-aws-environment/10230/3 "2024-10-13T10:54:19Z")

</div>

Okay thank you very much. I will be very glad if you could help me out.

Okay to be more detailed, what I did was:

- I launched an Ubuntu server in my AWS environment and logged into the server
- I updated the server, then used this command to install Ansible in the server “sudo apt install -y ansible”. I also went ahead to install python, Pip, boto, boto3 and the ansible dynamic inventory collection for my aws environment “ansible-galaxy collection install amazon.aws”.
- I created my aws\_ec2.yml file containing the following code to filter my servers with a specific tag from my said Region.  
plugin:aws\_ec2  
regions:  
us-west-2  
filters:  
tag:Env:  
-dev
- I updated my ansible.cfg file in the /etc/ansible directory at the following sections and with the following codes.  
[defaults]  
inventory = /etc/ansible/inventory/aws\_ec2.yml  
remote\_user = ec2-user  
private\_key\_file = /home/ubuntu/workernodes.pem  
ask\_pass = False  
deprecation\_warnings = False

[inventory]  
enable\_plugins = aws\_ec2

- I made sure to create a key pair file in the directory outlined in my ansible.cfg file to store the keys to my worker nodes to allow for ssh.
- I added an ec2 full permission role to my Ubuntu server
- Finally, I ran the following command to see if I could at least list the servers with tag “Env : dev” but unfortunately for me, it gave me an output saying “can’t use aws\_ec2.yml as inventory file” as the main issue.  
“ansible-inventory -i aws\_ec2.yml --list”.

I have tried several methods to bypass the issue but kept having the same error message

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [October 14, 2024, 1:07pm UTC](https://forum.ansible.com/t/issues-setting-up-dynamic-inventory-in-my-aws-environment/10230/4 "2024-10-14T13:07:59Z")

</div>

Can you use the code block formatting in your response, so we can see if your issue is the format of your code?

Also when you run an AWS command, does that work? Like `aws ec2 describe-instances`

---

<div class="post-metadata">

**Author:** ![Arreyetta\_Bawak\_Augu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/arreyetta_bawak_augu/32/5130_2.png) [@Arreyetta\_Bawak\_Augu](https://forum.ansible.com/u/Arreyetta_Bawak_Augu)\
**Post date:** [October 14, 2024, 1:30pm UTC](https://forum.ansible.com/t/issues-setting-up-dynamic-inventory-in-my-aws-environment/10230/5 "2024-10-14T13:30:30Z")

</div>

I used the code but it was in good formate. Just that when I pasted the code here, it doesn’t indent it as the original formate.

I didn’t try using _aws ec2 describe-instances_. When I tired calling the worker nodes with aws\_ec2.yml as my inventory file and it gave me the error message of “not being able to read it as my inventory file”, I started debugging immediately to solve the issue because i was so surprised as to why the error.

---

<div class="post-metadata">

**Author:** ![Arreyetta\_Bawak\_Augu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/arreyetta_bawak_augu/32/5130_2.png) [@Arreyetta\_Bawak\_Augu](https://forum.ansible.com/u/Arreyetta_Bawak_Augu)\
**Post date:** [October 14, 2024, 4:24pm UTC](https://forum.ansible.com/t/issues-setting-up-dynamic-inventory-in-my-aws-environment/10230/6 "2024-10-14T16:24:00Z")

</div>

Hello Sir

I finally succeeded to set it up. Thank you so much for taking out time to help me. I really appreciate
