Can you please try this:

    - debug: var="{{ item.id <http://vpc.subnets.id/> }}"
      when: vpc.subnets.az == "{{Azone1}}"
      with_items: vpc.subnets
for individual you can get like this but I am not sure:
    - debug: var=vpc.subnets[0].id <http://vpc.subnets.id/>
      when: vpc.subnets.az == "{{Azone1}}"

For complete example, please refer this:
https://github.com/arbabnazar/ansible-aws-vpc-ha-wordpress/blob/master/aws/tasks/vpc.yml
Thanks,

On Monday, December 14, 2015 at 8:54:23 PM UTC+5, Kjartan Clausen wrote:
>
> I'm trying to automate creating an AWS VPC with routes, subnets, 
> instances, RDS, etc.
> so I created the following yml:
>
> ---
>
> -   hosts: local
>     connection: local
> #    gather_facts: False
>     tags: provisioning
>     # Which region and AZ's should this VPC be in?
>     vars:
>       region: us-west-1
>       Azone1: us-west-1c
>       primary: 1c
>       Azone2: us-west-1b
>       secondary: 1b
>       vpc_name: "Test"
>       cidr: "94"
>
>     tasks:
>     - name: Create VPC
>       ec2_vpc:
>         state: present
>         cidr_block: 10.{{ cidr }}.0.0/16
>         resource_tags:
>           Name: "{{ vpc_name }}"
>         subnets:
>           - cidr: 10.{{ cidr }}.220.0/24
>             az: "{{ Azone1 }}"
>             resource_tags:
>               Name: "{{ vpc_name }}_NAT_{{ primary }}"
>           - cidr: 10.{{ cidr }}.221.0/24
>             az: "{{ Azone2 }}"
>             resource_tags:
>               Name: "{{ vpc_name }}_NAT_{{ secondary }}"
>         internet_gateway: True
>         route_tables:
>           - subnets:
>               - 10.{{ cidr }}.220.0/24
>               - 10.{{ cidr }}.221.0/24
>             routes:
>               - dest: 0.0.0.0/0
>                 gw: igw
>         region: "{{ region }}"
>       register: vpc
>
>     - debug: var=vpc.subnets
>
> # Problem statement
>     - debug: var=vpc.subnets.id
>       when: vpc.subnets.az == "{{Azone1}}"
>
> In order to create an instance on a given subnet I need to be able to 
> select that subnet, but my selection statement doesn't work.
> Output is:
> PLAY [local] 
> ******************************************************************
>
> GATHERING FACTS 
> ***************************************************************
> ok: [10.10.20.10]
>
> TASK: [Create VPC] 
> ************************************************************
> changed: [10.10.20.10]
>
> TASK: [debug var=vpc.subnets] 
> *************************************************
> ok: [10.10.20.10] => {
>     "var": {
>         "vpc.subnets": [
>             {
>                 "az": "us-west-1c",
>                 "cidr": "10.94.220.0/24",
>                 "id": "subnet-6555e73c",
>                 "resource_tags": {
>                     "Name": "Test_NAT_1c"
>                 }
>             },
>             {
>                 "az": "us-west-1b",
>                 "cidr": "10.94.221.0/24",
>                 "id": "subnet-3983fe5c",
>                 "resource_tags": {
>                     "Name": "Test_NAT_1b"
>                 }
>             }
>         ]
>     }
> }
>
> TASK: [debug var=vpc.subnets.id] 
> **********************************************
> fatal: [10.100.200.10] => error while evaluating conditional: 
> vpc.subnets.az == "us-west-1c"
>
> FATAL: all hosts have already failed -- aborting
>
> What do I need to do in order to get the us-west-1c subnet id as output?
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6e83fc28-2ef8-4c4f-bf6d-1e843a0c1d24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to