JSON Data Search with Ansible

Learn how to use Ansible to automate the search for specific data within a structured list.

Luca Berton

--

Introduction

Ansible is a powerful tool used for automation and configuration management. While it is commonly associated with tasks like server provisioning and application deployment, its flexibility allows it to be used for a wide variety of tasks, even something as simple as searching for a specific band member in a list of bands. In this article, we’ll create an Ansible playbook that searches for bands formed with a member named “Starr” and outputs the result.

Disclaimer

Full example available: https://www.redhat.com/sysadmin/ansible-jinja-lists-dictionaries

The Playbook

Below is the Ansible playbook designed for this task. It includes a list of bands, each with its members, formation year, and the decade they were most active. The playbook filters through this list to find any band that has a member named “Starr.”

---
- name: List bands formed with a member named Starr
hosts: localhost
gather_facts: no
vars:
bands:
- name: The Beatles
members:
- Lennon
- McCartney
- Harrison
- Starr
formed…

--

--

Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday