mirror of
https://github.com/ansible/awx.git
synced 2026-02-27 07:56:06 -03:30
properly support v2_playbook_on_notify in ansible 2.5+
see: https://github.com/ansible/awx/issues/1705 see: https://github.com/ansible/tower/issues/1205 related: https://github.com/ansible/ansible/pull/32633
This commit is contained in:
@@ -274,15 +274,14 @@ class BaseCallbackModule(CallbackBase):
|
|||||||
with self.capture_event_data('playbook_on_no_hosts_remaining'):
|
with self.capture_event_data('playbook_on_no_hosts_remaining'):
|
||||||
super(BaseCallbackModule, self).v2_playbook_on_no_hosts_remaining()
|
super(BaseCallbackModule, self).v2_playbook_on_no_hosts_remaining()
|
||||||
|
|
||||||
def v2_playbook_on_notify(self, result, handler):
|
def v2_playbook_on_notify(self, handler, host):
|
||||||
# NOTE: Not used by Ansible 2.x.
|
# NOTE: Not used by Ansible < 2.5.
|
||||||
event_data = dict(
|
event_data = dict(
|
||||||
host=result._host.get_name(),
|
host=host.get_name(),
|
||||||
task=result._task,
|
handler=handler.get_name(),
|
||||||
handler=handler,
|
|
||||||
)
|
)
|
||||||
with self.capture_event_data('playbook_on_notify', **event_data):
|
with self.capture_event_data('playbook_on_notify', **event_data):
|
||||||
super(BaseCallbackModule, self).v2_playbook_on_notify(result, handler)
|
super(BaseCallbackModule, self).v2_playbook_on_notify(handler, host)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
ansible_stats is, retoractively, added in 2.2
|
ansible_stats is, retoractively, added in 2.2
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ CALLBACK = os.path.splitext(os.path.basename(__file__))[0]
|
|||||||
PLUGINS = os.path.dirname(__file__)
|
PLUGINS = os.path.dirname(__file__)
|
||||||
with mock.patch.dict(os.environ, {'ANSIBLE_STDOUT_CALLBACK': CALLBACK,
|
with mock.patch.dict(os.environ, {'ANSIBLE_STDOUT_CALLBACK': CALLBACK,
|
||||||
'ANSIBLE_CALLBACK_PLUGINS': PLUGINS}):
|
'ANSIBLE_CALLBACK_PLUGINS': PLUGINS}):
|
||||||
|
from ansible import __version__ as ANSIBLE_VERSION
|
||||||
from ansible.cli.playbook import PlaybookCLI
|
from ansible.cli.playbook import PlaybookCLI
|
||||||
from ansible.executor.playbook_executor import PlaybookExecutor
|
from ansible.executor.playbook_executor import PlaybookExecutor
|
||||||
from ansible.inventory.manager import InventoryManager
|
from ansible.inventory.manager import InventoryManager
|
||||||
@@ -284,3 +285,29 @@ def test_callback_plugin_saves_custom_stats(executor, cache, playbook):
|
|||||||
assert json.load(f) == {'foo': 'bar'}
|
assert json.load(f) == {'foo': 'bar'}
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(os.path.join(private_data_dir))
|
shutil.rmtree(os.path.join(private_data_dir))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('playbook', [
|
||||||
|
{'handle_playbook_on_notify.yml': '''
|
||||||
|
- name: handle playbook_on_notify events properly
|
||||||
|
connection: local
|
||||||
|
hosts: all
|
||||||
|
handlers:
|
||||||
|
- name: my_handler
|
||||||
|
debug: msg="My Handler"
|
||||||
|
tasks:
|
||||||
|
- debug: msg="My Task"
|
||||||
|
changed_when: true
|
||||||
|
notify:
|
||||||
|
- my_handler
|
||||||
|
'''}, # noqa
|
||||||
|
])
|
||||||
|
@pytest.mark.skipif(ANSIBLE_VERSION < '2.5', reason="v2_playbook_on_notify doesn't work before ansible 2.5")
|
||||||
|
def test_callback_plugin_records_notify_events(executor, cache, playbook):
|
||||||
|
executor.run()
|
||||||
|
assert len(cache)
|
||||||
|
notify_events = [x[1] for x in cache.items() if x[1]['event'] == 'playbook_on_notify']
|
||||||
|
assert len(notify_events) == 1
|
||||||
|
assert notify_events[0]['event_data']['handler'] == 'my_handler'
|
||||||
|
assert notify_events[0]['event_data']['host'] == 'localhost'
|
||||||
|
assert notify_events[0]['event_data']['task'] == 'debug'
|
||||||
|
|||||||
Reference in New Issue
Block a user