0
votes

I want to run an ansible role, for all the ip address in the vpc which are running. How to get all the ip address of running instance in given vpc

Things: I have tired:

aws ec2 describe-instances --filters "Name=vpc-id, Values="vpc-******"" --query "Reservations[].Instances[].PrivateIpAddresses[*]" --output text

This is returning null

2

2 Answers

2
votes

The name of the parameter is PrivateIpAddress not PrivateIpAddresses as you can see from Json object

[
    [
        {
            "Monitoring": {
                "State": "disabled"
            },
            "PublicDnsName": "xxxx",
            "RootDeviceType": "ebs",
            "State": {
                "Code": 16,
                "Name": "running"
            },
            "EbsOptimized": false,
            "LaunchTime": "xxx",
            "PublicIpAddress": "xxx",
            "PrivateIpAddress": "xxxxx",
            "ProductCodes": [
            ....

so if you run your command as

aws ec2 describe-instances --filters "Name=vpc-id, Values="vpc-cda7c6a8"" --query "Reservations[*].Instances[*].PrivateIpAddress" --output text

you will have your expected result

0
votes

it's PrivateIPAddress, not Addresses

aws ec2 describe-instances --instance-ids --query Reservations[].Instances[].PrivateIpAddress

Hope this helps