Skip to content

Commit

Permalink
Revert "Fix missing delegate display (ansible#74370)"
Browse files Browse the repository at this point in the history
This reverts commit 3cff54d.
  • Loading branch information
samdoran committed May 3, 2021
1 parent a237b6c commit 62a2aeb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 24 deletions.
2 changes: 0 additions & 2 deletions changelogs/fragments/restore_delegate_label.yml

This file was deleted.

5 changes: 0 additions & 5 deletions lib/ansible/executor/task_executor.py
Expand Up @@ -728,11 +728,6 @@ def _evaluate_failed_when_result(result):
for k in plugin_vars:
result["_ansible_delegated_vars"][k] = cvars.get(k)

# note: here for callbacks that rely on this info to display delegation
for requireshed in ('ansible_host', 'ansible_port', 'ansible_user', 'ansible_connection'):
if requireshed not in result["_ansible_delegated_vars"] and requireshed in cvars:
result["_ansible_delegated_vars"][requireshed] = cvars.get(requireshed)

# and return
display.debug("attempt loop complete, returning result")
return result
Expand Down
16 changes: 7 additions & 9 deletions lib/ansible/plugins/callback/__init__.py
Expand Up @@ -21,7 +21,9 @@

import difflib
import json
import os
import sys
import warnings

from copy import deepcopy

Expand Down Expand Up @@ -102,15 +104,11 @@ def host_label(result):
"""Return label for the hostname (& delegated hostname) of a task
result.
"""
label = "%s" % result._host.get_name()
if result._task.delegate_to and result._task.delegate_to != result._host.get_name():
# show delegated host
label += " -> %s" % result._task.delegate_to
# in case we have 'extra resolution'
ahost = result._result.get('_ansible_delegated_vars', {}).get('ansible_host', result._task.delegate_to)
if result._task.delegate_to != ahost:
label += "(%s)" % ahost
return label
hostname = result._host.get_name()
delegated_vars = result._result.get('_ansible_delegated_vars', None)
if delegated_vars:
return "%s -> %s" % (hostname, delegated_vars['ansible_host'])
return "%s" % (hostname,)

def _run_is_verbose(self, result, verbosity=0):
return ((self._display.verbosity > verbosity or result._result.get('_ansible_verbose_always', False) is True)
Expand Down
10 changes: 2 additions & 8 deletions test/units/plugins/callback/test_callback.py
Expand Up @@ -32,10 +32,6 @@
from ansible.plugins.callback import CallbackBase


mock_task = MagicMock()
mock_task.delegate_to = None


class TestCallback(unittest.TestCase):
# FIXME: This doesn't really test anything...
def test_init(self):
Expand All @@ -54,15 +50,13 @@ def test_display_verbose(self):
self.assertIs(cb._display, display_mock)

def test_host_label(self):
result = TaskResult(host=Host('host1'), task=mock_task, return_data={})

result = TaskResult(host=Host('host1'), task=None, return_data={})
self.assertEquals(CallbackBase.host_label(result), 'host1')

def test_host_label_delegated(self):
mock_task.delegate_to = 'host2'
result = TaskResult(
host=Host('host1'),
task=mock_task,
task=None,
return_data={'_ansible_delegated_vars': {'ansible_host': 'host2'}},
)
self.assertEquals(CallbackBase.host_label(result), 'host1 -> host2')
Expand Down

0 comments on commit 62a2aeb

Please sign in to comment.