steampunk / steampunk.aws / 0.9.0 / module / ec2_subnet Manage EC2 VPC Subnets Authors: Manca Bizjak (@mancabizjak), Aljaz Kosir (@aljazkosir), Saso Stanovnik (@sstanovnik), Miha Dolinar (@mdolinar), Tadej Borovsak (@tadeboro) preview | supported by XLAB Steampunksteampunk.aws.ec2_subnet (0.9.0) — module
Install with ansible-galaxy collection install steampunk.aws:==0.9.0
collections: - name: steampunk.aws version: 0.9.0
Create, update or delete an AWS EC2 VPC Subnet.
- name: Create a subnet in the default VPC ec2_subnet: name: my-subnet-in-default-vpc cidr: 10.0.0.0/16
- name: Create a subnet in a non-default VPC and specific availability zone ec2_subnet: name: my-subnet vpc: vpc-123456 cidr: 10.0.0.0/16 availability_zone: use2-az2 register: my_subnet
- name: Update the subnet's setting for auto assigning public IPs to instances ec2_subnet: id: "{{ my_subnet.object.id }}" auto_assign_ip: true
- name: Clear all the subnet's tags ec2_subnet: id: "{{ my_subnet.object.id }}" clear_tags: true
- name: Delete a subnet ec2_subnet: id: "{{ my_subnet.object.id }}" state: absent
- name: Delete a subnet in a non-default VPC by providing a VPC ID and subnet CIDR block ec2_subnet: vpc: vpc-123456 cidr: 10.0.0.0/16 state: absent
- name: Delete a subnet in the default VPC by providing its CIDR block ec2_subnet: cidr: 10.0.0.0/16 state: absent
id: description: - ID of the resource to perform the task on. - If specified, this parameter is used to identify the resource. - Omit this parameter when you are first creating the resource. type: str vpc: description: - ID of the VPC for the target subnet. - In the absence of I(id), the value of this parameter will be used to uniquely identify the subnet together with I(cidr). - If omitted, the default VPC is assumed. type: str auth: description: - Parameters for authenticating with the AWS service. Each of them may be defined via environment variables. suboptions: access_key: description: - The AWS access key ID. If not set, the value of the AWS_ACCESS_KEY environment variable will be checked. - Mutually exclusive with I(profile). required: false type: str profile: description: - The name of the AWS profile configured with C(aws configure). - Can be used instead of explicitly specifying your access credentials and region. - Use C(default) to use the default profile. - Mutually exclusive with I(access_key) and I(secret_key). required: false type: str region: description: - The name of the AWS region. - If not set, the value of the AWS_REGION environment variable will be checked. - If you set a I(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: description: - The AWS secret access key. If not set, the value of the AWS_SECRET_KEY environment variable will be checked. - Mutually exclusive with I(profile). required: false type: str url: description: - 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. required: false type: str type: dict cidr: description: - IPv4 network range to assign to the subnet, in CIDR notation. - This parameter is required unless I(id) is provided. - In the absence of I(id), the value of this parameter will be used to uniquely identify the subnet within the desired I(vpc) or default VPC. type: str name: description: - Name of the subnet. - This parameter is required when first creating the subnet. type: str tags: description: - Metadata for the AWS resource as key/value pairs. - Keys and values are case-sensitive. type: dict state: choices: - present - absent default: present description: - Target state of the AWS resource. type: str clear_tags: default: false description: - Whether to clear any existing tags on the resource that are not explicitly stated in I(tags). - By default, existing tags are kept on the resource. - When this parameter is set to C(true), any pre-existing tags on the resource (including the name tag) are removed. To clear all tags except the name tag, make sure to provide the I(name) parameter. type: bool auto_assign_ip: default: false description: - Whether a public IPv4 address should be assigned to ENIs attached to instances launched from this subnet. type: bool availability_zone: description: - ID of the availability zone to create the AWS resource in. - If omitted, the availability zone will be selected by AWS. type: str
object: contains: auto_assign_ip: description: Whether a public IPv4 address is automatically assigned to instances in this subnet. returned: always type: bool availability_zone: description: The ID of the availability zone the subnet is in. returned: always type: str available_ip_address_count: description: The number of remaining private IPv4 addresses in the range of the subnet. returned: always type: int cidr: description: The CIDR block of the subnet. returned: always type: str id: description: The ID of the subnet. returned: always type: str tags: description: The tags assigned to the subnet. returned: always type: dict vpc: description: The ID of the VPC the subnet belongs to. returned: always type: str description: - An object representing an EC2 subnet. returned: success and I(state=present) sample: object: auto_assign_ip: true availability_zone: eun-az1 available_ip_address_count: 15 cidr: 192.0.2.0/24 id: subnet-123456 tags: mycompany-public: true vpc: vpc-123456 type: dict