I see what I was doing wrong. Thanks for this, your solution worked. On Thu, Aug 23, 2018 at 4:53 PM Kai Stian Olstad < [email protected]> wrote:
> On Thursday, 23 August 2018 21.03.14 CEST [email protected] wrote: > > I have a dict that looks like: > > > > "msg": [ > > { > > "assign_ipv6_address_on_creation": false, > > "availability_zone": "us-west-1a", > > "available_ip_address_count": 250, > > "cidr_block": "10.0.1.0/24", > > "default_for_az": false, > > "id": "subnet-030ff449eaea87042", > > "ipv6_cidr_block_association_set": [], > > "map_public_ip_on_launch": false, > > "state": "available", > > "subnet_id": "subnet-030ff449eaea87042", > > "tags": { > > "Name": "private-a" > > }, > > "vpc_id": "vpc-0a8c42654fe5f4a2b" > > }, > > { > > "assign_ipv6_address_on_creation": false, > > "availability_zone": "us-west-1a", > > "available_ip_address_count": 251, > > "cidr_block": "10.0.2.0/24", > > "default_for_az": false, > > "id": "subnet-0e2db57655e833a66", > > "ipv6_cidr_block_association_set": [], > > "map_public_ip_on_launch": false, > > "state": "available", > > "subnet_id": "subnet-0e2db57655e833a66", > > "tags": { > > "Name": "public-a" > > }, > > "vpc_id": "vpc-0a8c42654fe5f4a2b" > > }, > > <snip /> > > > > > and I'm attempting to extract subnet_id for only public subnets like so: > > > > - name: set public vpc subnets > > set_fact: > > vpc_public_subnet_ids: "{{ item | selectattr('Name', 'search', > > 'public.+') | map(attribute='subnet_id') | list }}" > > loop: "{{ vpc_subnet_facts.subnets }}" > > > > I've tried a number of ways to filter out this information but to no > avail. > > The most common error is *"Unexpected templating type error occurred on > ({{ > > item | selectattr('Name', 'search', 'public.+') | > > map(attribute='subnet_id') | list }}): expected string or buffer"}"* > > I feel as if I'm making some rather basic mistake here. Any help is > > appreciated. > > selectattr only works on list not dicts. > And you don't have a Name at that level only tags.Name > > So this should work > > - name: set public vpc subnets > set_fact: > vpc_public_subnet_ids: "{{ vpc_subnet_facts.subnets | > selectattr('tags.Name', 'search', 'public.+') | map(attribute='subnet_id') > | list }}" > > So you where very close to find the solution. > > -- > Kai Stian Olstad > > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/3103612.W4BkT6hQ3H%40x1. > For more options, visit https://groups.google.com/d/optout. > -- Justin Potts | Senior Software Engineer t: 347.932.5082 | [email protected] -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAB%2BJXHVSqfV5htOco76%3DkUuBO9RfAWirdrFTVD1oWMrBhZcP8w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
