Unable to create alb with Ansible

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