Skip to content

Commit

Permalink
Merge pull request #327 from pguermo/master
Browse files Browse the repository at this point in the history
Keep the callback provided in the environment variable

Reviewed-by: https://github.com/apps/ansible-zuul
  • Loading branch information
ansible-zuul[bot] authored Jul 29, 2019
2 parents 732efec + 89cf573 commit 39644c6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ansible_runner/runner_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def prepare(self):
python_path = self.env.get('PYTHONPATH', os.getenv('PYTHONPATH', ''))
if python_path and not python_path.endswith(':'):
python_path += ':'
self.env['ANSIBLE_CALLBACK_PLUGINS'] = callback_dir
self.env['ANSIBLE_CALLBACK_PLUGINS'] = ':'.join(filter(None,(self.env.get('ANSIBLE_CALLBACK_PLUGINS'), callback_dir)))
if 'AD_HOC_COMMAND_ID' in self.env:
self.env['ANSIBLE_STDOUT_CALLBACK'] = 'minimal'
else:
Expand Down
14 changes: 14 additions & 0 deletions test/integration/callback/other_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from ansible.plugins.callback import CallbackBase


class CallbackModule(CallbackBase):
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'aggregate'
CALLBACK_NAME = 'other_callback'

def v2_playbook_on_play_start(self, play):
pass

def v2_runner_on_ok(self, result):
pass

12 changes: 10 additions & 2 deletions test/integration/test_display_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@

import pytest

HERE = os.path.abspath(os.path.dirname(__file__))


@pytest.fixture()
def executor(tmpdir, request):
private_data_dir = six.text_type(tmpdir.mkdir('foo'))

playbooks = request.node.callspec.params.get('playbook')
playbook = list(playbooks.values())[0]
envvars = request.node.callspec.params.get('envvars')
envvars = envvars.update({"ANSIBLE_DEPRECATION_WARNINGS": "False"}) if envvars is not None else {"ANSIBLE_DEPRECATION_WARNINGS": "False"}

r = init_runner(
private_data_dir=private_data_dir,
inventory="localhost ansible_connection=local",
envvars={"ANSIBLE_DEPRECATION_WARNINGS": "False"},
envvars=envvars,
playbook=yaml.safe_load(playbook)
)

Expand Down Expand Up @@ -57,7 +61,11 @@ def executor(tmpdir, request):
var: results
'''}, # noqa
])
def test_callback_plugin_receives_events(executor, event, playbook):
@pytest.mark.parametrize('envvars', [
{'ANSIBLE_CALLBACK_PLUGINS': os.path.join(HERE, 'callback')},
{'ANSIBLE_CALLBACK_PLUGINS': ''}
])
def test_callback_plugin_receives_events(executor, event, playbook, envvars):
executor.run()
assert len(list(executor.events))
assert event in [task['event'] for task in executor.events]
Expand Down

0 comments on commit 39644c6

Please sign in to comment.