Hi Raphael, If code lives in "module_utils" in Ansible, these pieces of code can be inserted into other modules. This is currently not a configurable directory though where you can drop your own snippets.
I think basically this would warrant a pull request to add a configurable "module_utils" path that would be searched by the ModuleReplacer code in addition to the core. "Please advice - is this left out on purpose or just very badly documented & hidden away?" It doesn't exist now as a user configurable directory, so this is somewhat jumping to a wrong conclusion. Ansible follows a "YAGNI" philosophy, most open source development is also based on itch-scratching. AKA, nobody needed this. As for testing, you really should write integration tests. --Michael On Fri, Feb 21, 2014 at 5:38 PM, Raphael Randschau < [email protected]> wrote: > Hey there, > > while working on [ansible-rails][1] I came across a problem I have not yet > been able to solve by just reading and interpreting the ansible source code: > > how can I share common dependencies between multiple, custom commands? > E.g. given the following role directory structure: > > /example > /example/library > /example/library/command_a > /example/library/command_b > /example/library/shared_utility.py > /example/library/__init__.py > > shared_utility.py contains classes used in both command_a AND command_b. > > The way I understand ansible right now is that when command_a is used > inside a playbook/ role it's source is expanded and copied to the server > (sie ModuleReplacer inside the ansible source). > However, due to this processing, I can't just import shared_utility, > because it's not copied to the remote server. > > My question now is this: how do I import shared code into ansible > commands? And equally important: how do I properly test these custom > commands without much hackery (I'm talking about good old unit tests in > this case!) > > Please advice - is this left out on purpose or just very badly documented > & hidden away? > > Thanks, > Raphael > > [1]:https://github.com/nicolai86/ansible-rails > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/93c6462b-75d2-4b16-8ae0-e02cc580f540%40googlegroups.com > . > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEVJ8QPrPLxC9auYBWQdLesSUc66S3rjpFDpxfzMLdM%3DSDvQtA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
