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.

Top comments (0)