Iterating Dictionaries with Ansible Roles

Joseph D. Marhee
Nov 6 · 2 min read

I recently began re-working my infrastructure lab’s automation from scratch, and for my DNS server, I decided to take a simple approach: I want to define a hostname and address, and have it applied. Ansible supports a dictionary, key-value based data structure, so a definition like:

some-host:
some-key: some-value
some-other-key: some-other-value

is valid for use in an Ansible playbook, and iterable using the with_items syntax.

Keep the story going. Sign up for an extra free read.

You've completed your member preview for this month, but when you sign up for a free Medium account, you get one more story.
Already have an account? Sign in

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade