DEV Community

Discussion on: Ansible AWS EC2 Dynamic Inventory Plugin

Collapse
 
vumdao profile image
🚀 Vu Dao 🚀

Please check one of the following

  1. Your aws_profile as you set in ~/.aws/config
  2. Tags of the resources
Collapse
 
dishantpandya profile image
Dishant Pandya

Still, I am not able to get it working.

#aws_ec2.yaml
---
plugin: aws_ec2
aws_profile: default
regions:
  - eu-west-1
filters:
  instance-state-name : running
Enter fullscreen mode Exit fullscreen mode
# ansible.cfg

[default]
enable_plugins = aws_ec2
inventory       = hosts
host_key_checking = False
stdout_callback = debug
Enter fullscreen mode Exit fullscreen mode
# ~/.aws/config

[default]
region = eu-west-1
output = json
Enter fullscreen mode Exit fullscreen mode

Output of Describe Instances:

$ aws ec2 describe-instances

{
    "Reservations": [
        {
            "Groups": [],
            "Instances": [
                {
                    "AmiLaunchIndex": 0,
                    "ImageId": "ami-0aef57767f5404a3c",
                    "InstanceId": "i-03da2458c13c728e3",
                    "InstanceType": "t2.micro",
                    "KeyName": "astroamoreapp",
                    "LaunchTime": "2020-12-08T12:27:17+00:00",
                    "Monitoring": {
                        "State": "disabled"
                    }
                 .....
                 .....
                }
            ],
            "OwnerId": "493670244487",
            "ReservationId": "r-033c3a14ba52afbf7"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

Output of ansible-inventory -i aws_ec2.yml --list

[WARNING]: Unable to parse /home/dishant/nodejs-ansible/aws_ec2.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
vumdao profile image
🚀 Vu Dao 🚀

Did you install aws_ec2 plugin? Read more here: docs.ansible.com/ansible/latest/co...

Plus, it requires boto3 and botocore python modules.

Thread Thread
 
dishantpandya profile image
Dishant Pandya

Thanks! its working, actually the issue was with the file name, as mentioned in the given documentation its should end end with aws_ec2.(yml/yaml)

Thread Thread
 
vumdao profile image
🚀 Vu Dao 🚀

Great!