ansible-inventory --list .. how to get part of info

hello

i am using ansible-inventory with AWS

I see all EC2 details … great

Is it possible from the output to extract only some info

eg

To list AWS resources execute the below command:

1

./ec2.py --list

This will return the entire list of AWS resources in JSON.

{
“_meta”: {
“hostvars”: {
“65.201.11.219”: {
“ansible_host”: “34.201.11.219”,
“ec2__in_monitoring_element”: false,
“ec2_account_id”: “209518873002”,
“ec2_ami_launch_index”: “0”,
“ec2_architecture”: “x86_64”,
“ec2_block_devices”: {
“xvda”: “vol-008e156f7bc2d99ad”
},
“ec2_client_token”: “”,
“ec2_dns_name”: “ec2-65-201-11-219.compute-1.amazonaws.com”,
“ec2_ebs_optimized”: false,
“ec2_eventsSet”: “”,
“ec2_group_name”: “”,
“ec2_hypervisor”: “xen”,
“ec2_id”: “i-09689b6635c10f3cf2”,
“ec2_image_id”: “ami-467ca739”,
“ec2_instance_profile”: “”,
“ec2_instance_type”: “t2.micro”,
“ec2_ip_address”: “34.222.11.219”,
“ec2_item”: “”,
“ec2_kernel”: “”,
“ec2_key_name”: “ec2_private.pem”,
“ec2_launch_time”: “2018-07-04T20:10:57.000Z”
}}}}

so say i need only below

ansible_host": “34.201.11.219”,
“ec2_image_id”: “ami-467ca739”,
“ec2_instance_type”: “t2.micro”,
“ec2_ip_address”: “34.222.11.219”,

Any suggestions Please

I think some of you may say use other modules for that …

Just wanted to know if that is the way or we can do anything else

As i know there are functions/tools to manipulate the jason o/p … but that be a overkill & hence use other modules like community.aws.ec2_instance_info

thanks

ec2.py is deprecated. Please use https://github.com/ansible-collections/amazon.aws/blob/main/plugins/inventory/aws_ec2.py

You can specify filters to keep only the information you require. Check example section for more information - https://github.com/ansible-collections/amazon.aws/blob/c5d31d709487afc5df19c60245698532352d80e3/plugins/inventory/aws_ec2.py#L104

Thanks Abhijeet