Member-only story
Filter A List By Its Attributes — Ansible selectattr filter
How to list only the enabled features in a network interface using Ansible System Information (Facts) and selectattr filter.
How to Filter A List By Its Attributes in an Ansible Playbook?
I’m going to show you a live demo with some simple Ansible code.
I’m Luca Berton and welcome to today’s episode of Ansible Pilot.
selectattr filter in Ansible Playbook?
- `
{{ users|selectattr(“is_active”) }}
` - `
{{ users|selectattr(“email”, “none”) }}
`
Today we’re talking about Ansible `selectattr
` Jinja filter.
Filters a sequence of objects by applying a test to the specified attribute of each object, and only selecting the objects with the test succeeding.
If no test is specified, the attribute’s value will be evaluated as a boolean.
The two examples explain how-to for a specific attribute or value using a `users
` list example.