Need help with a jinja2 filter

I’m trying to get the id of the security group that doesn’t have ‘Default’ in the name. In other words grab “sg-0a2fea74.”

This is what “sg_facts | json_query('instances[].groups[])” spits out:

“groups”: [
{
“id”: “sg-828889fe”,
“name”: “Default / EC2 / Linux Ansible Clients”
},
{
“id”: “sg-0a2fea74”,
“name”: “EC2 / Shib Prd”
},
{
“id”: “sg-eb8b8087”,
“name”: “Default / Linux Admin Access”
}
],

My with_items filter below is not working but illustrates what I’m trying to do. Anyone know how I can get this done? – Thanks

  • name: Gather facts

ec2_remote_facts:
region: us-east-1
filters:
“tag:Resource_group_id”: “{{ resource_group_id_tag }}”
register: sg_facts

  • debug: var={{ item }}
    with_items: “{{ sg_facts | json_query(‘instances[].groups[].[?name !~ ‘Default’].id’) }}”

Actually “sg_facts | json_query('instances[].groups[])” spits out:

TASK [debug] *******************************************************************
ok: [localhost] => (item={u’id’: u’sg-828889fe’, u’name’: u’Default / EC2 / Linux Ansible Clients’}) => {
“<type ‘dict’>”: “VARIABLE IS NOT DEFINED!”,
“item”: {
“id”: “sg-828883fe”,
“name”: “Default / EC2 / Linux Ansible Clients”
}
}
ok: [localhost] => (item={u’id’: u’sg-eb8b8087’, u’name’: u’Default / Linux Admin Access / Port 22’}) => {
“<type ‘dict’>”: “VARIABLE IS NOT DEFINED!”,
“item”: {
“id”: “sg-eb8b8087”,
“name”: “Default / Linux Admin Access / Port 22”
}
}
ok: [localhost] => (item={u’id’: u’sg-0a2fea74’, u’name’: u’EC2 / ITS Shib Prd’}) => {
“<type ‘dict’>”: “VARIABLE IS NOT DEFINED!”,
“item”: {
“id”: “sg-0a2fea74”,
“name”: “EC2 / ITS Shib Prd”
}
}