Have you thought about breaking out some jinja expressions to manipulate
the structure? In particular the selectrattr() filter.
http://jinja.pocoo.org/docs/dev/templates/
Here is a similar example I did
- hosts: localhost
connection: local
vars:
config:
frontend:
- id: 1
value: test1
tls:
- key: key1
domain: domain1
- id: 2
value: test2
backend:
- id: 3
- id: 4
tasks:
- debug: var=item
with_items: config.frontend
- debug: var=item
with_items: config.frontend | selectattr("tls", "defined") | list
And then the output
(ansible)[ec2-user@ip-10-0-0-226 playbooks]$ ansible-playbook
test_withitems.yml
PLAY [localhost]
**************************************************************
GATHERING FACTS
***************************************************************
ok: [localhost]
TASK: [debug var=item]
********************************************************
ok: [localhost] => (item={'tls': [{'domain': 'domain1', 'key': 'key1'}],
'id': 1, 'value': 'test1'}) => {
"item": {
"id": 1,
"tls": [
{
"domain": "domain1",
"key": "key1"
}
],
"value": "test1"
}
}
ok: [localhost] => (item={'id': 2, 'value': 'test2'}) => {
"item": {
"id": 2,
"value": "test2"
}
}
TASK: [debug var=item]
********************************************************
ok: [localhost] => (item={'tls': [{'domain': 'domain1', 'key': 'key1'}],
'id': 1, 'value': 'test1'}) => {
"item": {
"id": 1,
"tls": [
{
"domain": "domain1",
"key": "key1"
}
],
"value": "test1"
}
}
PLAY RECAP
********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
That should give a list of all frontends that have a tls attribute defined.
Thanks!
Michael
--
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/7d540723-1226-4574-a067-482c1c916c99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.