I want to create two hosted zones 1 private and 1 public. When I create it manually on AWS console it gets created and the private hosted zone is associated with my VPC. However through Ansible only 1 zone is created. If the task to create private hosted zone is first then the private hosted zone is created and public is not created. The ID's for both zone is returned as identical. If the task for public hosted zone is first then only the public hosted zone gets created and identical IDs are returned. I really don't understand why it is having like this. No errors are thrown.
---
- name: Create VPC
ec2_vpc:
state: present
dns_hostnames: yes
dns_support: yes
cidr_block: "{{ vpc_ip_range }}"
resource_tags: "{{ vpc_resource_tags }}"
subnets:
- cidr: "{{ vpc_subnet_app_ip_range }}"
az: "{{ vpc_subnet_app_az }}"
resource_tags: "{{ vpc_subnet_app_resource_tags }}"
- cidr: "{{ vpc_subnet_db_ip_range }}"
az: "{{ vpc_subnet_db_az }}"
resource_tags: "{{ vpc_subnet_db_resource_tags }}"
- cidr: "{{ vpc_subnet_private_ip_range }}"
az: "{{ vpc_subnet_private_az }}"
resource_tags: "{{ vpc_subnet_private_resource_tags }}"
internet_gateway: True
route_tables:
- subnets:
- "{{ vpc_subnet_app_ip_range }}"
- "{{ vpc_subnet_db_ip_range }}"
- "{{ vpc_subnet_private_ip_range }}"
routes:
- dest: 0.0.0.0/0
gw: igw
region: "{{ vpc_region }}"
register: vpc
- name: Set VPC ID in a variable
set_fact:
vpc_id: "{{ vpc.vpc_id }}"
- name: Print VPC variable
debug:
msg: "{{ vpc_id }}"
Script for Creating Hosted Zones:
---
- name: Create private hosted Zone
route53_zone:
zone: "{{ private_hosted_zone_name }}"
state: present
vpc_id: "{{ vpc_id }}"
vpc_region: "{{ vpc_region }}"
register: private_hosted_zone
- name: Print private zone id
debug:
msg: "{{ private_hosted_zone.set.zone_id }}"
- name: Set private zone ID in a variable
set_fact:
private_zone_id: "{{ private_hosted_zone.set.zone_id }}"
- name: Create public hosted Zone
route53_zone:
zone: "{{ public_hosted_zone_name }}"
state: present
register: public_hosted_zone
- name: Print public zone id
debug:
msg: "{{ public_hosted_zone.set.zone_id }}"
- name: Set public zone ID in a variable
set_fact:
public_zone_id: "{{ public_hosted_zone.set.zone_id }}"
Any help will be highly appreciated.