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, 2019 in Ansible by Rajeev
1,597 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, 2019 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, 2019 in Ansible by Sai
751 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, 2019 in Ansible by William
854 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,939 views
+2 votes
1 answer
0 votes
1 answer

How do I add apt key by id from a keyserver? - Ansible

Hey @Altis, you can use the module ...READ MORE

answered Feb 11, 2019 in Ansible by Kyra
3,670 views
0 votes
1 answer

Deploy nginx using Ansible

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

answered Jan 8, 2019 in Ansible by Barbara
1,007 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP