aws_ec2 inventory plugin brings up empty list

97 views
Skip to first unread message

marcel...@aurea.com

unread,
Jan 5, 2019, 3:00:20 PM1/5/19
to Ansible Project
Hi, I'm trying to use the aws_ec2 inventory plugin but it's always showing an empty list with no errors:

# ansible-inventory -vvv -i ./inventory/aws_ec2.yml --list
ansible
-inventory 2.7.5
  config file
= /ansible/ansible.cfg
  configured
module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python
module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location
= /usr/local/bin/ansible-inventory
  python version
= 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
Using /ansible/ansible.cfg as config file
Parsed /ansible/inventory/aws_ec2.yml inventory source with aws_ec2 plugin
{
   
"_meta": {
       
"hostvars": {}
   
},
   
"all": {
       
"children": [
           
"aws_ec2",
           
"ungrouped"
       
]
   
},
   
"aws_ec2": {},
   
"ungrouped": {}
}

my ansible.cfg:

[inventory]
enable_plugins
= advanced_host_list, constructed, yaml, auto

and the aws_ec2.yml

plugin: aws_ec2
regions
:
 
- us-east-1


What's weird is that the ec2.py script works and brings the full host list. I'm pretty sure I'm doing something stupid but I can't figure out what.


jegan...@gmail.com

unread,
Jan 7, 2019, 8:56:01 AM1/7/19
to Ansible Project
Please see below suggestion for your query 


+ Example playbook


plugin: aws_ec2
boto_profile: default   #AWS profile name which is in .aws/credentials file
regions:
  - us-east-1
hostnames:
  
  - private-ip-address



+ Edit your ec.ini file as below 

From :

vpc_destination_variable = ip_address

To:

vpc_destination_variable = private_ip_address


+ I have not changed  'ansible.cfg' file


+ My same result for the above playbook


ansible-inventory  ec2_plug.yml --list

[DEPRECATION WARNING]: ANSIBLE_HOSTS option, The variable is misleading as it can be a list of hosts and/or paths to inventory sources , use ANSIBLE_INVENTORY instead. This feature will
be removed in version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
{
    "_meta": {
        "hostvars": {
            "54.88.15.199": {
                "ansible_ssh_host": "54.88.15.199",
                "ec2__in_monitoring_element": false,
                "ec2_account_id": "910842549320",
                "ec2_ami_launch_index": "0",
                "ec2_architecture": "x86_64",
                "ec2_block_devices": {
                    "xvda": "vol-0d20fa054ec75855d"
                },
                "ec2_client_token": "",
                "ec2_dns_name": "ec2-54-88-15-199.compute-1.amazonaws.com",
                "ec2_ebs_optimized": false,
                "ec2_eventsSet": "",
                "ec2_group_name": "",
                "ec2_hypervisor": "xen",
                "ec2_id": "i-093dc8fd02c5c148a",
                "ec2_image_id": "ami-009d6802948d06e52",
                "ec2_instance_profile": "",
                "ec2_instance_type": "t2.micro",
                "ec2_ip_address": "54.88.15.199",
                "ec2_item": "",
                "ec2_kernel": "",
                "ec2_key_name": "key_pair",
                "ec2_launch_time": "2019-01-07T11:24:21.000Z",
                "ec2_monitored": false,
                "ec2_monitoring": "",
                "ec2_monitoring_state": "disabled",
                "ec2_persistent": false,
                "ec2_placement": "us-east-1c",
                "ec2_platform": "",
                "ec2_previous_state": "",
                "ec2_previous_state_code": 0,
                "ec2_private_dns_name": "ip-172-31-87-246.ec2.internal",
                "ec2_private_ip_address": "172.31.87.246",
                "ec2_public_dns_name": "ec2-54-88-15-199.compute-1.amazonaws.com",
                "ec2_ramdisk": "",
                "ec2_reason": "",
                "ec2_region": "us-east-1",
                "ec2_requester_id": "",
                "ec2_root_device_name": "/dev/xvda",
                "ec2_root_device_type": "ebs",
                "ec2_security_group_ids": "sg-0b80b71ff0bca16a4",
                "ec2_security_group_names": "launch-wizard-1",
                "ec2_sourceDestCheck": "true",
                "ec2_spot_instance_request_id": "",
                "ec2_state": "running",
                "ec2_state_code": 16,
                "ec2_state_reason": "",
                "ec2_subnet_id": "subnet-d395e1ff",
                "ec2_virtualization_type": "hvm",
                "ec2_vpc_id": "vpc-77f9bd0e",
                "my_user_name": "test"
            }
        }
    },
    "all": {
        "children": [
            "ami_009d6802948d06e52",
            "aws",
            "ec2",
            "i-093dc8fd02c5c148a",
            "key_key_pair",
            "security_group_launch_wizard_1",
            "tag_none",
            "type_t2_micro",
            "ungrouped",
            "us-east-1",
            "us-east-1c",
            "vpc_id_vpc_77f9bd0e"
        ]
    },
    "ami_009d6802948d06e52": {
        "hosts": [
            "54.88.15.199"
        ]
    },
    "aws": {},
    "ec2": {
        "hosts": [
            "54.88.15.199"
        ]
    },
    "i-093dc8fd02c5c148a": {
        "hosts": [
            "54.88.15.199"
        ]
    },
    "key_key_pair": {
        "hosts": [
            "54.88.15.199"
        ]
    },
    "security_group_launch_wizard_1": {
        "hosts": [
            "54.88.15.199"
        ]
    },
    "tag_none": {
        "hosts": [
            "54.88.15.199"
        ]
    },
    "type_t2_micro": {
        "hosts": [
            "54.88.15.199"
        ]
    },
    "ungrouped": {},
    "us-east-1": {
        "hosts": [
            "54.88.15.199"
        ]
    },
    "us-east-1c": {
        "hosts": [
            "54.88.15.199"
        ]
    },
    "vpc_id_vpc_77f9bd0e": {
        "hosts": [
            "54.88.15.199"
        ]
    }
}

Marcelo T Melo

unread,
Jan 7, 2019, 9:26:35 AM1/7/19
to ansible...@googlegroups.com
It worked, thank you.



Aurea
Marcelo T Melo
 
 
 
Java Chief Software Architect
Skype: marcelotmelo


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1b33224e-25ed-46b6-98e2-b48716322850%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages