【发布时间】:2019-06-14 01:15:44
【问题描述】:
以下显示了我在 AWS 中创建 VPC 的 Ansible 剧本。
Playbook 将执行:
- 使用 CIDR 创建 VPC
- 然后创建路由表
- 然后标记路由表
- 最后创建路由表。
代码如下:
---
- name: To set up internet gateway
hosts: all
tasks:
- name: creating vpc
ec2_vpc:
region: ap-northeast-1
state: present
cidr_block: 20.0.0.0/16
resource_tags: { "Name":"Test" }
register: vpc
- name: Creating internet gateway for the vpc created
ec2_vpc_igw:
region: ap-northeast-1
state: present
vpc_id: "{{ vpc.vpc_id }}"
register: igw
- name: Tagging the gateway we just created
ec2_tag:
resource: "{{ igw.gateway_id }}"
#with_items: igw.gateway_id
state: present
region: ap-northeast-1
tags:
Name: test-test
- name: Creating route table
ec2_vpc_route_table:
region: ap-northeast-1
propagating_vgw_ids: yes
vpc_id: "{{ vpc.vpc_id }}"
subnets:
- '20.0.0.0/16'
routes:
- dest: 0.0.0.0/0
gateway_id: "{{ igw.gateway_id }}"
但是当我执行我的剧本时,我收到如下错误
failed: [172.30.1.237] => {"failed": true, "parsed": false}
Traceback (most recent call last):
File "/home/ubuntu/.ansible/tmp/ansible-tmp-1450103975.3-140284971977416/ec2_vpc_route_table", line 2411, in <module>
main()
File "/home/ubuntu/.ansible/tmp/ansible-tmp-1450103975.3-140284971977416/ec2_vpc_route_table", line 588, in main
result = ensure_route_table_present(connection, module)
File "/home/ubuntu/.ansible/tmp/ansible-tmp-1450103975.3-140284971977416/ec2_vpc_route_table", line 519, in ensur e_route_table_present
check_mode=check_mode)
File "/home/ubuntu/.ansible/tmp/ansible-tmp-1450103975.3-140284971977416/ec2_vpc_route_table", line 398, in ensure_propagation
dry_run=check_mode)
File "/usr/local/lib/python2.7/dist-packages/boto/vpc/__init__.py", line 1492, in enable_vgw_route_propagation
return self.get_status('EnableVgwRoutePropagation', params)
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 1227, in get_status
raise self.ResponseError(response.status, response.reason, body)
boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>Gateway.NotAttached</Code><Message>resource True</Message></Error></Errors><RequestI D>4f34cefd-08c2-4180-b532-dd6e9e74f7e7</RequestID></Response>
除了缩进的错误之外,我在哪里犯了错误。 它创建了 VPC 以及互联网网关。但是在使用路由表模块时。我收到错误消息。
【问题讨论】:
标签: amazon-ec2 ansible ansible-playbook vpc