下圖顯示了我在AWS中創建VPC的Ansible手冊。使用Ansible在AWS中創建VPC
在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,以及互聯網網關。但在使用路由表模塊時。我收到錯誤。
我試着通過添加下面的幾行來修改你的playbook,但它是說沒有定義igw。 – Bidyut
- 名稱:標記新的互聯網網關創建 ec2_tag: 資源: 「{{igw.gateway_id}}」 狀態:目前 區域:AP-東北-1 標籤: 名稱:測試網關 – Bidyut
可以使用igw變量只能在vpc創建中使用。要標記igw你可以使用vpc註冊變量。在vpc變量中,您將擁有igw編號 –