Merge pull request #1029 from anoek/release_2.4.5

Fix for tasks breaking when using 'yum' with ansible 1.9.4
This commit is contained in:
Akita Noek
2016-02-25 10:43:28 -05:00
3 changed files with 36 additions and 13 deletions

View File

@@ -218,8 +218,9 @@ class AdHocCommandEvent(CreatedModifiedModel):
('runner_on_unreachable', _('Host Unreachable'), True), ('runner_on_unreachable', _('Host Unreachable'), True),
# Tower won't see no_hosts (check is done earlier without callback). # Tower won't see no_hosts (check is done earlier without callback).
#('runner_on_no_hosts', _('No Hosts Matched'), False), #('runner_on_no_hosts', _('No Hosts Matched'), False),
# Tower should probably never see skipped (no conditionals). # Tower will see skipped (when running in check mode for a module that
#('runner_on_skipped', _('Host Skipped'), False), # does not support check mode).
('runner_on_skipped', _('Host Skipped'), False),
# Tower does not support async for ad hoc commands. # Tower does not support async for ad hoc commands.
#('runner_on_async_poll', _('Host Polling'), False), #('runner_on_async_poll', _('Host Polling'), False),
#('runner_on_async_ok', _('Host Async OK'), False), #('runner_on_async_ok', _('Host Async OK'), False),

View File

@@ -123,8 +123,8 @@ class RunAdHocCommandTest(BaseAdHocCommandTest):
self.assertFalse(ad_hoc_command.passwords_needed_to_start) self.assertFalse(ad_hoc_command.passwords_needed_to_start)
self.assertTrue(ad_hoc_command.signal_start()) self.assertTrue(ad_hoc_command.signal_start())
ad_hoc_command = AdHocCommand.objects.get(pk=ad_hoc_command.pk) ad_hoc_command = AdHocCommand.objects.get(pk=ad_hoc_command.pk)
self.check_job_result(ad_hoc_command, 'failed') self.check_job_result(ad_hoc_command, 'successful')
self.check_ad_hoc_command_events(ad_hoc_command, 'unreachable') self.check_ad_hoc_command_events(ad_hoc_command, 'skipped')
@mock.patch('awx.main.tasks.BaseTask.run_pexpect', return_value=('canceled', 0)) @mock.patch('awx.main.tasks.BaseTask.run_pexpect', return_value=('canceled', 0))
def test_cancel_ad_hoc_command(self, ignore): def test_cancel_ad_hoc_command(self, ignore):

View File

@@ -66,8 +66,12 @@ CENSOR_FIELD_WHITELIST=[
'skip_reason', 'skip_reason',
] ]
def censor(obj): def censor(obj, no_log=False):
if obj.get('_ansible_no_log', False): if not isinstance(obj, dict):
if no_log:
return "the output has been hidden due to the fact that 'no_log: true' was specified for this result"
return obj
if obj.get('_ansible_no_log', no_log):
new_obj = {} new_obj = {}
for k in CENSOR_FIELD_WHITELIST: for k in CENSOR_FIELD_WHITELIST:
if k in obj: if k in obj:
@@ -80,8 +84,12 @@ def censor(obj):
new_obj['censored'] = "the output has been hidden due to the fact that 'no_log: true' was specified for this result" new_obj['censored'] = "the output has been hidden due to the fact that 'no_log: true' was specified for this result"
obj = new_obj obj = new_obj
if 'results' in obj: if 'results' in obj:
for i in xrange(len(obj['results'])): if isinstance(obj['results'], list):
obj['results'][i] = censor(obj['results'][i]) for i in xrange(len(obj['results'])):
obj['results'][i] = censor(obj['results'][i], obj.get('_ansible_no_log', no_log))
elif obj.get('_ansible_no_log', False):
obj['results'] = "the output has been hidden due to the fact that 'no_log: true' was specified for this result"
return obj return obj
@@ -479,6 +487,7 @@ class AdHocCommandCallbackModule(BaseCallbackModule):
def __init__(self): def __init__(self):
self.ad_hoc_command_id = int(os.getenv('AD_HOC_COMMAND_ID', '0')) self.ad_hoc_command_id = int(os.getenv('AD_HOC_COMMAND_ID', '0'))
self.rest_api_path = '/api/v1/ad_hoc_commands/%d/events/' % self.ad_hoc_command_id self.rest_api_path = '/api/v1/ad_hoc_commands/%d/events/' % self.ad_hoc_command_id
self.skipped_hosts = set()
super(AdHocCommandCallbackModule, self).__init__() super(AdHocCommandCallbackModule, self).__init__()
def _log_event(self, event, **event_data): def _log_event(self, event, **event_data):
@@ -489,6 +498,19 @@ class AdHocCommandCallbackModule(BaseCallbackModule):
def runner_on_file_diff(self, host, diff): def runner_on_file_diff(self, host, diff):
pass # Ignore file diff for ad hoc commands. pass # Ignore file diff for ad hoc commands.
def runner_on_ok(self, host, res):
# When running in check mode using a module that does not support check
# mode, Ansible v1.9 will call runner_on_skipped followed by
# runner_on_ok for the same host; only capture the skipped event and
# ignore the ok event.
if host not in self.skipped_hosts:
super(AdHocCommandCallbackModule, self).runner_on_ok(host, res)
def runner_on_skipped(self, host, item=None):
super(AdHocCommandCallbackModule, self).runner_on_skipped(host, item)
self.skipped_hosts.add(host)
if os.getenv('JOB_ID', ''): if os.getenv('JOB_ID', ''):
CallbackModule = JobCallbackModule CallbackModule = JobCallbackModule