ansible/ansible — pull request #3187 by sergevanginderachter (2013-06-12 22:17:39+00:00)
Title: add support for callback_plugins/ relative to playbook

Hi @mpdehaan. This PR only to get feedback on implementation details.

As discussed on irc, callbacks are initialized too early by `lib/ansible/playbook/__init__.py` (at utils import), way before any basedir gets pushed.

You told me to patch `ansible-playbook`and to push basedir there, but the place where callback_loader() is loaded lives in `lib/ansible/playbook`, so it has to happen there, at least AFAICS.

I checked other plugin types, but those all work with optional *_plugins/ dirs relative to basedirs. So only callback_plugins have a problem here.

This patch moves the initialization (calling `utils.plugins.callback_loader.all()`) into a function, which gets loaded only after the playbook code can do an extra `utils.plugins.push_basedir()` call.

Optionally, I patched the `push_basedir` function to only push a new basedir, not every basedir call (which gets multiple basedirs repeated in `_basedir`)

Questions:
* Can you confirm if this patch is done the way it should or you would expect? I got a little confused when searching where callbacks got initialized, but I think this is the only place to patch.
* This patch only adds support for playbooks, hence for the `bin/ansible-playbook` command. Didn't look into `bin/ansible` support yet, but I'd expect this would also need this extra support, if only to be consequent as other plugins work with that. Not sure yet what the basedir is in this case. just cwd, or something relative to the inventory.