mateothegreat.aws_vpc_create

创建 AWS VPC

功能:

  • 创建(可选)对等连接。
  • 支持对所有资源进行标记。

此角色将创建一个新的 AWS VPC,包括:

  • 对等连接
  • Internet 网关
  • NAT 网关
  • 路由表
  • 子网

要求

pip install ansible boto3 boto

变量

aws_vpc_create:
  profile: "default"            # AWS 凭证文件的配置文件名称。
  name: "test-1"                # 要创建的 VPC 名称。
  region: "eu-central-1"        # AWS 区域。
  cidr: "201.0.0.0/16"          # 整个 VPC 的 CIDR。
  internet_gateway: "true"      # 创建一个 Internet 网关。
  nat_gateway: "true"           # 创建一个带有弹性 IP 的 NAT 网关。
  allow_duplicate_name: "false" # 如果存在同名的 VPC,不会失败。
  allow_duplicate_cidr: "false" # 如果存在相同 CIDR 的 VPC,不会失败。
  purge_cidrs: "true"           # 如果使用现有 VPC,删除所有 CIDR。
  peering:
    - name: "test-1-peer"
      vpc_id: "vpc-0504d01b93f46e610"
      region: "eu-central-1"
      cidr: "22.16.0.0/16"
      update_accepter_route_table: "true" # 在接受者的路由表中添加回到此 VPC 的路由。
  dns:
    enable_support: "true"      # 为此 VPC 启用 DNS 支持。
    enable_hostnames: "true"    # 为此 VPC 启用主机名解析。
  subnets:
    - name: "public-1"
      type: "public"
      az: "eu-central-1a"
      cidr: "201.0.1.0/24"
    - name: "public-2"
      type: "public"
      cidr: "201.0.2.0/24"
      az: "eu-central-1b"
    - name: "private-1"
      type: "private"
      cidr: "201.0.3.0/24"
      az: "eu-central-1a"
    - name: "private-2"
      type: "private"
      cidr: "201.0.4.0/24"
      az: "eu-central-1b"
  tags:
    created_by: "Matthew Davis"

示例用法

将以下内容添加到名为 playbook.yaml 的文件中:

- hosts: monitoring
  roles:
    - role: "mateothegreat.aws_vpc_create"
      vars:
        aws_vpc_create:
          profile: "default"            # AWS 凭证文件的配置文件名称。
          name: "test-1"                # 要创建的 VPC 名称。
          region: "eu-central-1"        # AWS 区域。
          cidr: "201.0.0.0/16"          # 整个 VPC 的 CIDR。
          internet_gateway: "true"      # 创建一个 Internet 网关。
          nat_gateway: "true"           # 创建一个带有弹性 IP 的 NAT 网关。
          allow_duplicate_name: "false" # 如果存在同名的 VPC,不会失败。
          allow_duplicate_cidr: "false" # 如果存在相同 CIDR 的 VPC,不会失败。
          purge_cidrs: "true"           # 如果使用现有 VPC,删除所有 CIDR。
          peering:
            - name: "test-1-peer"
              vpc_id: "vpc-0504d01b93f46e610"
              region: "eu-central-1"
              cidr: "22.16.0.0/16"
              update_accepter_route_table: "true" # 在接受者的路由表中添加回到此 VPC 的路由。
          dns:
            enable_support: "true"      # 为此 VPC 启用 DNS 支持。
            enable_hostnames: "true"    # 为此 VPC 启用主机名解析。
          subnets:
            - name: "public-1"
              type: "public"
              az: "eu-central-1a"
              cidr: "201.0.1.0/24"
            - name: "public-2"
              type: "public"
              cidr: "201.0.2.0/24"
              az: "eu-central-1b"
            - name: "private-1"
              type: "private"
              cidr: "201.0.3.0/24"
              az: "eu-central-1a"
            - name: "private-2"
              type: "private"
              cidr: "201.0.4.0/24"
              az: "eu-central-1b"
          tags:
            created_by: "Matthew Davis"

使用命令 ansible-playbook -i <你的清单文件> playbook.yaml 运行。

联系方式

你可以通过 https://matthewdavis.io 联系我。

关于项目

Provision a complete AWS VPC.

安装
ansible-galaxy install mateothegreat.aws_vpc_create
许可证
Unknown
下载
120
拥有者
🚀 ☞ Senior Software Architect, Cloud Engineer & DevOps Advocate. ✌