Filter lists by attributes - Ansible

0 votes

I have a variable "network" registered in Ansible:

{
    "addresses": {
        "private_ext": [
            {
                "type": "fixed",
                "addr": "172.16.2.105"
            }
        ],
        "private_man": [
            {
                "type": "fixed",
                "addr": "172.16.1.105"
            },
            {
                "type": "floating",
                "addr": "10.90.80.11"
            }
        ]
    }
}

Is it possible to get the IP address ("addr") with type="floating"?

Jan 14 in Ansible by Rajeev
20 views

1 answer to this question.

0 votes

Filter the dicts using selectattr_filter in combination with equalto_test. Something like this/:

network.addresses.private_man | selectattr("type", "equalto", "fixed")

This execution requires you to have Jinja2 v2.8 or later

answered Jan 14 by Haider

Related Questions In Ansible

0 votes
1 answer

Virtualization Infrastructure supported by Ansible

Yes, Vagrant supports Ansible, in-fact Ansible is ...READ MORE

answered Jan 25 in Ansible by Sai
16 views
0 votes
1 answer

Ansible roles change workflow order by moving handlers.

Flush handlers with meta: flush_handlers before the task that ...READ MORE

answered Mar 12 in Ansible by William
19 views
0 votes
2 answers

Issue creating AWS VPC with Ansible

You can use the details given in ...READ MORE

answered Aug 16, 2018 in Ansible by Priyaj
• 56,160 points
134 views
+13 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Deploy nginx using Ansible

Follow these steps: Use the following command in ...READ MORE

answered Jan 8 in Ansible by Barbara
29 views