DEV Community

Cover image for Sharing code in Ansible Collections
XLAB Steampunk
XLAB Steampunk

Posted on

Sharing code in Ansible Collections

Any Ansible Collection of non-trivial size will eventually have to deal with shared code. One option is to copy-paste the code all around, but let us not go there, OK? So, we need a place to store shared code.

For Ansible modules, things are straightforward: any shared code goes into the plugins/module_utils directory. Other types of Ansible plugins can also use code from the module_utils directory. But because of some technical details that we will not go into today, not all shared code can live there. At least not without sanity tests yelling at us, that is ;)

So, where should non-module shared code go then? There used to be no official directory for it. However, this all changed when the plugins/plugin_utils became the official location for shared plugin code.

So now you know. And if you want more information, you can find it here. Or ping us, we’re happy to help.

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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

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

Okay