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.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

👋 Kindness is contagious

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

Okay