ec2_subnet_info – List EC2 VPCs

Retrieve information about AWS EC2 Virtual Private Clouds.

Examples

- name: List subnets across all VPCs in the selected region
  ec2_subnet_info:
  register: result

- name: List subnets in a specific VPC
  ec2_subnet_info:
    vpc: vpc-2s3726csbs3
    ids: subnet-s9324d4da4
  register: result

- name: List several subnets by name
  ec2_subnet_info:
    names:
      - my-subnet-1
      - my-subnet-2
  register: result

- name: List all available subnets
  ec2_subnet_info:
    filters:
      state: available
  register: result

Parameters

auth (optional)

Parameters for authenticating with the AWS service. Each of them may be defined via environment variables.

type: dict
access_key (optional)

The AWS access key ID. If not set, the value of the AWS_ACCESS_KEY environment variable will be checked.

Mutually exclusive with profile.

type: str
profile (optional)

The name of the AWS profile configured with aws configure.

Can be used instead of explicitly specifying your access credentials and region.

Use default to use the default profile.

Mutually exclusive with access_key and secret_key.

type: str
region (optional)

The name of the AWS region.

If not set, the value of the AWS_REGION environment variable will be checked.

If you set a profile that specifies a default region, that region is used and you can omit this parameter. Use this parameter to override the profile’s default region.

type: str
secret_key (optional)

The AWS secret access key. If not set, the value of the AWS_SECRET_KEY environment variable will be checked.

Mutually exclusive with profile.

type: str
url (optional)

The URL to the AWS service related to the resource. By default, this is automatically determined through the region parameter.

If not set explicitly, the value of the AWS_<SERVICE>_URL environment variable will be used.

The services currently supported are EC2 and S3.

type: str
filters (optional)

Filters to use when querying AWS resources. They must be provided as key/value pairs.

Keys and values are case-sensitive and must be strings.

Each key can have multiple values, provided as a list. Within these values, any value must match for the AWS resource to be included.

When multiple filters are provided, the result contains AWS resources matching all of them.

If a filter is specified in filters and also in another top-level parameter, the filter in the top-level parameter has precedence. The two are not merged.

If a module accepts a top-level parameter for querying the AWS resources, and you also specify the filter it corresponds to via filters, the top-level parameter has precedence.

type: dict
ids (optional)

Perform the operation for the specified resources.

type: list
names (optional)

Limit the results to the resources with specified names.

type: list
vpc (optional)

ID of the VPC.

May be used to limit the results to subnets in the given VPC only.

type: str

Return Values

objects (success), list, {‘objects’: [{‘id’: ‘subnet-123456’, ‘vpc’: ‘vpc-123456’, ‘availability_zone’: ‘eun-az1’, ‘cidr’: ‘192.0.2.0/24’, ‘auto_assign_ip’: True, ‘tags’: {‘mycompany-public’: True}, ‘available_ip_address_count’: 15}]}

A list of objects representing EC2 subnets.

id (always), str,

The ID of the subnet.

vpc (always), str,

The ID of the VPC the subnet belongs to.

availability_zone (always), str,

The ID of the availability zone the subnet is in.

cidr (always), str,

The CIDR block of the subnet.

auto_assign_ip (always), bool,

Whether a public IPv4 address is automatically assigned to instances in this subnet.

tags (always), dict,

The tags assigned to the subnet.

available_ip_address_count (always), int,

The number of remaining private IPv4 addresses in the range of the subnet.