# Unable to create alb with Ansible

**URL:** <https://forum.ansible.com/t/unable-to-create-alb-with-ansible/28597>\
**Category:** Ansible Project\
**Tags:** awx\
**Created:** [September 18, 2018, 9:41am UTC](https://forum.ansible.com/t/unable-to-create-alb-with-ansible/28597 "2018-09-18T09:41:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Subrat\_Mahapatra](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@Subrat\_Mahapatra](https://forum.ansible.com/u/Subrat_Mahapatra)\
**Post date:** [September 18, 2018, 9:41am UTC](https://forum.ansible.com/t/unable-to-create-alb-with-ansible/28597/1 "2018-09-18T09:41:42Z")

</div>

Hi There,

I am able to get the list of subnets for a VPC ID or tag name with the help of set\_fact.  
While using the subnets (Subnet Output of set\_fact) to create an ALB I am getting error as “load balancer cannot be attached to multiple subnets in the same availability zone”

Here is the playbook

- name: Getting facts about subnet and VPC from an Instance with Tags  
ec2\_instance\_facts:  
filters:  
“tag:Name”: AWX  
region: eu-west-1  
register: output

- name: displaying output  
debug: var=output.instances.0.vpc\_id

- name: Querying subnets from the vpc id  
ec2\_vpc\_subnet\_facts:  
filters:  
vpc-id: “{{ output.instances.0.vpc\_id }}”  
region: eu-west-1  
register: subnetoutput

- name : displaying subnet zone  
set\_fact:  
subnetzone: “{{ subnetoutput.subnets | map(attribute=‘availability\_zone’) | list }}”  
register: subnetzoneout

- name: displaying subnet id  
set\_fact:  
subnetid: “{{ subnetoutput.subnets | map(attribute=‘subnet\_id’) | list }}”  
register: subnetidout

- name: displaying subnetoutput  
set\_fact:  
hostlist: “{{ subnetoutput.subnets | map(attribute=‘availability\_zone’) | list }}”  
register: subout

- name: Creating Target Group  
elb\_target\_group:  
region: eu-west-1  
name: DemoTargetGroup  
protocol: https  
port: 443  
vpc\_id: “{{ output.instances.0.vpc\_id }}”  
health\_check\_path: /  
successful\_response\_codes: “{{response\_codes}}”  
state: present  
register: tgoutput

- name: Creating ALB

elb\_application\_lb:  
name: DemoALB-new  
region: eu-west-1  
security\_groups:

- sg-02a1426d

scheme: internet-facing  
#zones: “{{ subout.ansible\_facts.hostlist }}”  
subnets: “{{ subnetidout.ansible\_facts.subnetid }}”

# - “{{ subnetidout.ansible\_facts.subnetid.0 }}”

# - “{{ subnetidout.ansible\_facts.subnetid.1 }}”

Red marked not working but green working, I want to set the subnet-ID as dynamic not static
