Ansible Nested Lists: Loop Over Lists of Lists (with_subelements, flatten)
By Luca Berton · Published 2024-01-01 · Category: installation
How to work with nested lists in Ansible playbooks. Use subelements, flatten, and nested loops to iterate over complex data structures with practical examples.
Introduction
CfgMgmtCamp 2025, the premier event for systems administrators, DevOps engineers, and Infrastructure as Code enthusiasts, is taking place in Ghent, Belgium, from February 3–5, 2025. Among the many notable speakers, Luca Berton, a globally recognized Ansible expert, will share his expertise on automating AI-driven environments.
Session Overview: Automating AI-Powered Graph Databases with Ansible
Title: Automating AI-Powered Graph Databases with Ansible: A Neo4j GenAI Case Study Date & Time: February 4, 2025, 14:00–14:25 Location: Ansible 1 (B.1.017) Session Type: Short Talk (25 minutes)
In this insightful session, Luca Berton will demonstrate: • Automating the deployment of Neo4j GenAI environments using Ansible playbooks. • Integrating OpenAI for retrieval-augmented generation (RAG) tasks. • Best practices for configuring, managing, and optimizing AI-powered graph databases in hybrid cloud environments.
This talk is tailored for IT professionals looking to streamline complex AI setups using modern Infrastructure as Code (IaC) techniques. Expect hands-on demonstrations and actionable takeaways to enhance your automation journey.
About Luca Berton
Luca Berton is a seasoned Ansible Automation Expert and the author of best-selling books, including: • Ansible for Kubernetes by Example: Automate Your Kubernetes Cluster • Ansible for VMware by Example
With over 15 years of experience, Luca has been a key contributor to the open-source community. He has worked with Red Hat and JPMorgan Chase & Co., leading projects in automation, infrastructure hardening, and hybrid cloud deployments.
Don’t Miss This Event
CfgMgmtCamp 2025 offers a unique platform to connect with thought leaders and explore the latest in configuration management, automation, and DevOps. Luca Berton's session promises to be a highlight for anyone passionate about cutting-edge AI and Ansible automation.
For more details and registration, visit CfgMgmtCamp 2025.
---
Resources
Check out Luca Berton’s books and resources to dive deeper into Ansible automation: • Ansible by Example: 200+ Automation Examples • Ansible for Kubernetes by Example
Want to support Luca’s work? Donate on Patreon or Buy Me a Coffee.
Working with Nested Lists
Flatten nested lists
Loop over list of dictionaries with sub-lists
with_subelements (nested iteration)
Nested loop (cartesian product)
Modern loop with product filter
Accessing Nested Data
FAQ
When should I use with_subelements vs loop + subelements filter?
They're equivalent. The filter syntax is more modern:
How do I flatten only one level deep?
How do I handle optional sub-lists?
Use default([]) to handle missing keys:
Category: installation