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
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
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
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
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.
Hello Sir
I finally succeeded to set it up. Thank you so much for taking out time to help me. I really appreciate