ec2_vpc - configure AWS virtual private clouds

New in version 1.4.

DEPRECATED

Removed in Ansible:
version: 2.5
Why: Replaced by dedicated modules.
Alternative: Use ec2_vpc_net along with supporting modules including ec2_vpc_igw, ec2_vpc_route_table, ec2_vpc_subnet, ec2_vpc_dhcp_option, ec2_vpc_nat_gateway, ec2_vpc_nacl.

Synopsis

  • Create or terminates AWS virtual private clouds. This module has a dependency on python-boto.

Requirements

The below requirements are needed on the host that executes this module.

  • python >= 2.6
  • boto

Parameters

Parameter Choices/Defaults Comments
aws_access_key Default:
None
AWS access key. If not set then the value of the AWS_ACCESS_KEY_ID, AWS_ACCESS_KEY or EC2_ACCESS_KEY environment variable is used.

aliases: ec2_access_key, access_key
aws_secret_key Default:
None
AWS secret key. If not set then the value of the AWS_SECRET_ACCESS_KEY, AWS_SECRET_KEY, or EC2_SECRET_KEY environment variable is used.

aliases: ec2_secret_key, secret_key
cidr_block
The cidr block representing the VPC, e.g. 10.0.0.0/16, required when state=present.
dns_hostnames
    Choices:
  • yes
  • no
Toggles the "Enable DNS hostname support for instances" flag.
dns_support
    Choices:
  • yes
  • no
Toggles the "Enable DNS resolution" flag.
ec2_url Default:
None
Url to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints). Ignored for modules where region is required. Must be specified for all other modules if region is not used. If not set then the value of the EC2_URL environment variable, if any, is used.
instance_tenancy
    Choices:
  • default
  • dedicated
The supported tenancy options for instances launched into the VPC.
internet_gateway
    Choices:
  • yes
  • no
Toggle whether there should be an Internet gateway attached to the VPC.
profile
(added in 1.6)
Default:
None
Uses a boto profile. Only works with boto >= 2.24.0.
region
The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used. See http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region

aliases: aws_region, ec2_region
resource_tags
required

(added in 1.6)
A dictionary array of resource tags of the form { tag1: value1, tag2: value2 }. - Tags in this list are used in conjunction with CIDR block to uniquely identify a VPC in lieu of vpc_id. Therefore, if CIDR/Tag combination does not exist, a new VPC will be created. VPC tags not on this list will be ignored. Prior to 1.7, specifying a resource tag was optional.
route_tables Default:
None
A dictionary array of route tables to add of the form: { subnets: [172.22.2.0/24, 172.22.3.0/24,], routes: [{ dest: 0.0.0.0/0, gw: igw},], resource_tags: ... }. Where the subnets list is those subnets the route table should be associated with, and the routes list is a list of routes to be in the table. The special keyword for the gw of igw specifies that you should the route should go through the internet gateway attached to the VPC. gw also accepts instance-ids, interface-ids, and vpc-peering-connection-ids in addition igw. resource_tags is optional and uses dictionary form: { "Name": "public", ... }. This module is currently unable to affect the "main" route table due to some limitations in boto, so you must explicitly define the associated subnets or they will be attached to the main table implicitly. As of 1.8, if the route_tables parameter is not specified, no existing routes will be modified.
security_token
(added in 1.6)
Default:
None
AWS STS security token. If not set then the value of the AWS_SECURITY_TOKEN or EC2_SECURITY_TOKEN environment variable is used.

aliases: access_token
state
required
    Choices:
  • present
  • absent
Create or terminate the VPC.
subnets Default:
None
A dictionary array of subnets to add of the form { cidr: ..., az: ... , resource_tags: ... }.
Where az is the desired availability zone of the subnet, optional.
Tags resource_tags use dictionary form { "Environment":"Dev", "Tier":"Web", ...}, optional.
resource_tags see resource_tags for VPC below. The main difference is subnet tags not specified here will be deleted.
All VPC subnets not in this list will be removed as well.
As of 1.8, if the subnets parameter is not specified, no existing subnets will be modified.'
validate_certs
(added in 1.5)
    Choices:
  • no
  • yes
When set to "no", SSL certificates will not be validated for boto versions >= 2.6.0.
vpc_id Default:
None
A VPC id to terminate when state=absent.
wait
    Choices:
  • yes
  • no
Wait for the VPC to be in state 'available' before returning.
wait_timeout Default:
300
How long before wait gives up, in seconds.

Notes

Note

  • If parameters are not set within the module, the following environment variables can be used in decreasing order of precedence AWS_URL or EC2_URL, AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY or EC2_ACCESS_KEY, AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY or EC2_SECRET_KEY, AWS_SECURITY_TOKEN or EC2_SECURITY_TOKEN, AWS_REGION or EC2_REGION
  • Ansible uses the boto configuration file (typically ~/.boto) if no credentials are provided. See http://boto.readthedocs.org/en/latest/boto_config_tut.html
  • AWS_REGION or EC2_REGION can be typically be used to specify the AWS region, when required, but this can also be configured in the boto config file

Examples

# Note: None of these examples set aws_access_key, aws_secret_key, or region.
# It is assumed that their matching environment variables are set.

# Basic creation example:
    - ec2_vpc:
        state: present
        cidr_block: 172.23.0.0/16
        resource_tags: { "Environment":"Development" }
        region: us-west-2
# Full creation example with subnets and optional availability zones.
# The absence or presence of subnets deletes or creates them respectively.
    - ec2_vpc:
        state: present
        cidr_block: 172.22.0.0/16
        resource_tags: { "Environment":"Development" }
        subnets:
          - cidr: 172.22.1.0/24
            az: us-west-2c
            resource_tags: { "Environment":"Dev", "Tier" : "Web" }
          - cidr: 172.22.2.0/24
            az: us-west-2b
            resource_tags: { "Environment":"Dev", "Tier" : "App" }
          - cidr: 172.22.3.0/24
            az: us-west-2a
            resource_tags: { "Environment":"Dev", "Tier" : "DB" }
        internet_gateway: True
        route_tables:
          - subnets:
              - 172.22.2.0/24
              - 172.22.3.0/24
            routes:
              - dest: 0.0.0.0/0
                gw: igw
          - subnets:
              - 172.22.1.0/24
            routes:
              - dest: 0.0.0.0/0
                gw: igw
        region: us-west-2
      register: vpc

# Removal of a VPC by id
    - ec2_vpc:
        state: absent
        vpc_id: vpc-aaaaaaa
        region: us-west-2
# If you have added elements not managed by this module, e.g. instances, NATs, etc then
# the delete will fail until those dependencies are removed.

Status

This module is flagged as deprecated and will be removed in version 2.5. For more information see DEPRECATED.

Author

  • Carson Gee (@carsongee)

Hint

If you notice any issues in this documentation you can edit this document to improve it.

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.5/modules/ec2_vpc_module.html