# Deploy Subnets into Different availability zones using Ansible.

**URL:** <https://forum.ansible.com/t/deploy-subnets-into-different-availability-zones-using-ansible/20024>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [December 15, 2015, 5:56pm UTC](https://forum.ansible.com/t/deploy-subnets-into-different-availability-zones-using-ansible/20024 "2015-12-15T17:56:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bhotu](https://avatars.discourse-cdn.com/v4/letter/b/439d5e/32.png) [@Bhotu](https://forum.ansible.com/u/Bhotu)\
**Post date:** [December 15, 2015, 5:56pm UTC](https://forum.ansible.com/t/deploy-subnets-into-different-availability-zones-using-ansible/20024/1 "2015-12-15T17:56:19Z")

</div>

I am Working on putting subnets into different availability zones with the help of ansible. I want to put subnet1 into us-east-1a, then subnet2 into us-east-1b and so on. Currently I can only be able to put servers onto us-east-1a only. Here is the ansible scripts.

```auto
---
- name: Create AWS VPC and Subnets
  hosts: localhost
  connection: local
  gather_facts: false
  vars:
      region: us-east-1
      prefix: mahela_ansible
      az1: us-east-1a
      az2: us-east-1b
      az3: us-east-1c
 tasks:
 - name: Create VPC
   local_action:
     module: ec2_vpc
     region: "{{ region }}"
     cidr_block: 10.123.0.0/16
     resource_tags: '{"Name":"{{ prefix }}"}'
     subnets:
      - name: Cassandra Subnet
        cidr: 10.123.0.0/24
        az: "{{ az1 }}"
        resource_tags: '{"Name":"{{ prefix }}_cassandra"}'

      - name: MongoDB Subnet
        cidr: 10.123.1.0/24
        az: "{{ az2 }}"
        resource_tags: '{"Name":"{{ prefix }}_Mongodb"}'

      - name: Elastic Search
        cidr: 10.123.2.0/24
        az: "{{ az3 }}"
        resource_tags: '{"Name":"{{ prefix }}_elasticsearch"}'

```

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [December 15, 2015, 6:46pm UTC](https://forum.ansible.com/t/deploy-subnets-into-different-availability-zones-using-ansible/20024/2 "2015-12-15T18:46:24Z")

</div>

> I am Working on putting subnets into different availability zones with  
> the help of ansible. I want to put subnet1 into us-east-1a, then  
> subnet2 into us-east-1b and so on. Currently I can only be able to put  
> servers onto us-east-1a only. Here is the ansible scripts.

What happens when you try?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![Bhotu](https://avatars.discourse-cdn.com/v4/letter/b/439d5e/32.png) [@Bhotu](https://forum.ansible.com/u/Bhotu)\
**Post date:** [December 15, 2015, 6:49pm UTC](https://forum.ansible.com/t/deploy-subnets-into-different-availability-zones-using-ansible/20024/3 "2015-12-15T18:49:29Z")

</div>

Hi I can only find all the subnets in the same availability zones which is us-east-1a only. I want each of my subnets into different availability zones in AWS.

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [December 17, 2015, 4:00pm UTC](https://forum.ansible.com/t/deploy-subnets-into-different-availability-zones-using-ansible/20024/4 "2015-12-17T16:00:57Z")

</div>

> Hi I can only find all the subnets in the same availability zones which  
> is us-east-1a only. I want each of my subnets into different  
> availability zones in AWS.

Hmm, I don't have any other great ideas, then -- setting the 'az'  
parameter in the elements of the 'subnets' list does the right thing when  
I try it. (I haven't tried your exact example, but something similar when  
I set up a VPC at AWS a while ago.) I did encounter an error where AWS  
wouldn't let me create a subnet in a particular AZ (us-east-1c, I think),  
but that gave an obvious error, it didn't just drop the subnet into a  
different AZ.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 18, 2015, 8:05am UTC](https://forum.ansible.com/t/deploy-subnets-into-different-availability-zones-using-ansible/20024/5 "2015-12-18T08:05:41Z")

</div>

Can you try to use this technique on line#26  
[https://github.com/arbabnazar/ansible-aws-vpc-ha-wordpress/blob/master/aws/tasks/vpc.yml#L26](https://github.com/arbabnazar/ansible-aws-vpc-ha-wordpress/blob/master/aws/tasks/vpc.yml#L26)  
For complete reference, check the webserver creation playbook as well.
