Hi Everyone, I am need of help to make it work in order to add the nat
instance id as gw for private subnet inside the routing table.
Here is my vpc playbook:
/tasks/vpc.yml
-----------------
---
- name: VPC | Creating an AWS VPC inside mentioned Region
local_action:
module: ec2_vpc
region: "{{ vpc_region }}"
state: present
cidr_block: "{{ vpc_cidr_block }}"
resource_tags: { "Name":"{{ vpc_name }}_vpc" }
subnets: "{{ vpc_subnets }}"
internet_gateway: yes
route_tables: "{{ public_subnet_rt }}"
=====
here is my vars/vpc.yml file:
---
ec2_inst_id: i-abc1432c
# Variables for VPC
vpc_name: tendo
vpc_region: ap-southeast-2
vpc_cidr_block: 172.25.0.0/16
public_cidr: 172.25.10.0/24
public_az: "{{ vpc_region}}b"
private_cidr: 172.25.20.0/24
private_az: "{{ vpc_region }}a"
nat_private_ip: 172.25.10.10
# Please don't change the variables below, until you know what you are doing
#
# Subnets Defination for VPC
vpc_subnets:
- cidr: "{{ public_cidr }}" # Public Subnet
az: "{{ public_az }}"
resource_tags: { "Name":"{{ vpc_name }}_public_subnet" }
- cidr: "{{ private_cidr }}" # Private Subnet
az: "{{ private_az }}"
resource_tags: { "Name":"{{ vpc_name }}_private_subnet" }
## Routing Table for Public Subnet
public_subnet_rt:
- subnets:
- "{{ public_cidr }}"
routes:
- dest: 0.0.0.0/0
gw: igw
When I run the above playbook it work fine:
ansible-playbook -i 'localhost,' --connection=local site.yml -vvvv 2 ↵
PLAY [all]
********************************************************************
TASK: [VPC | Creating an AWS VPC inside mentioned Region]
*********************
<127.0.0.1> region=ap-southeast-2 cidr_block=172.25.0.0/16 state=present
<127.0.0.1>
<127.0.0.1>
<127.0.0.1> u'LANG=C LC_CTYPE=C /usr/bin/python
/Users/arbab/.ansible/tmp/ansible-tmp-1427103212.79-152394513704427/ec2_vpc;
rm -rf /Users/arbab/.ansible/tmp/ansible-tmp-1427103212.79-152394513704427/
>/dev/null 2>&1']
changed: [localhost -> 127.0.0.1] => {"changed": true, "subnets": [{"az":
"ap-southeast-2b", "cidr": "172.25.10.0/24", "id": "subnet-70845e15",
"resource_tags": {"Name": "tendo_public_subnet"}}, {"az":
"ap-southeast-2a", "cidr": "172.25.20.0/24", "id": "subnet-8d1fdffa",
"resource_tags": {"Name": "tendo_private_subnet"}}], "vpc": {"cidr_block":
"172.25.0.0/16", "dhcp_options_id": "dopt-261e0244", "id": "vpc-9cea26f9",
"region": "ap-southeast-2", "state": "available"}, "vpc_id": "vpc-9cea26f9"}
---------------------------------------------------------------------------------------------------
Here is the problem when I redefine the VPC with the nat-instance id as gw.
=========================================================
- name: NAT | NAT Route
set_fact:
private_subnet_rt: '{{ lookup("template",
"../templates/nat_routes.json.j2") }}'
- name: redefine vpc
local_action:
module: ec2_vpc
region: "{{ vpc_region }}"
state: present
cidr_block: "{{ vpc_cidr_block }}"
resource_tags: { "Name":"{{ vpc_name }}_vpc" }
subnets: "{{ vpc_subnets }}"
internet_gateway: yes
route_tables: "{{ private_subnet_rt }}"
Here are the content of the nat_routes.json.j2:
- subnets:
- {{ public_cidr }}
routes:
- dest: 0.0.0.0/0
gw: "igw"
- subnets:
- {{ private_cidr }}
routes:
- dest: 0.0.0.0/0
gw: {{ ec2_inst_id }}
I got this error when I run the above playbook after Creating the NAT
instance:
TASK: [redefine vpc]
**********************************************************
<127.0.0.1> region=ap-southeast-2 cidr_block=172.25.0.0/16 state=present
route_tables=-
subnets:
- 172.25.10.0/24
routes:
- dest: 0.0.0.0/0
gw: igw
- subnets:
- 172.25.20.0/24
routes:
- dest: 0.0.0.0/0
gw: i-abc1432c
failed: [localhost -> 127.0.0.1] => {"failed": true, "parsed": false}
Traceback (most recent call last):
File
"/Users/arbab/.ansible/tmp/ansible-tmp-1427101746.8-192243069214182/ec2_vpc",
line 2413, in <module>
main()
File
"/Users/arbab/.ansible/tmp/ansible-tmp-1427101746.8-192243069214182/ec2_vpc",
line 618, in main
(vpc_dict, new_vpc_id, subnets_changed, changed) = create_vpc(module,
vpc_conn)
File
"/Users/arbab/.ansible/tmp/ansible-tmp-1427101746.8-192243069214182/ec2_vpc",
line 425, in create_vpc
for route in rt['routes']:
TypeError: string indices must be integers, not str
Can you please point me that where I am making mistake.
Thanks
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/06c7932e-3f1e-447a-bd96-71888bc65d8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.