DEV Community

Cover image for Parameterizing Ansible roles
XLAB Steampunk
XLAB Steampunk

Posted on

3

Parameterizing Ansible roles

We often talk about how high-quality Ansible content enables us to enforce the desired state on target hosts. Module parameters play a crucial role here because we use them to describe the expected result. But what about Ansible roles that do not have parameters?

Ansible roles use variables to customize their behavior. And since variables serve as parameters in Ansible roles, we, Ansible content creators, should document them with the same care as we document module parameters. The rules we should follow when describing role variable are:

  1. Each variable must have a short description.
  2. Variables with default values must note what the default value is and why we chose it.
  3. If the valid variable values come from a predefined set, we must list that set's content.

Where should we put this information? Right now, the best places are the reference section of the documentation site or the top-level README file in the Ansible Collection. That last one is incredibly convenient since Ansible Galaxy displays the README file content.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay