diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index ea7331ab89..1af45412f3 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -393,7 +393,7 @@ class Runner(object): if actual_port is not None: actual_port = int(actual_port) conn = self.connector.connect(actual_host, actual_port) - if delegate_to: + if delegate_to or host != actual_host: conn.delegate = host diff --git a/test/TestPlayBook.py b/test/TestPlayBook.py index fd57f328bb..55d552da95 100644 --- a/test/TestPlayBook.py +++ b/test/TestPlayBook.py @@ -111,12 +111,12 @@ class TestPlaybook(unittest.TestCase): filename = os.path.join(self.stage_dir, filename) return filename - def _run(self, test_playbook): + def _run(self, test_playbook, host_list='test/ansible_hosts'): ''' run a module and get the localhost results ''' self.test_callbacks = TestCallbacks() self.playbook = ansible.playbook.PlayBook( playbook = test_playbook, - host_list = 'test/ansible_hosts', + host_list = host_list, module_path = 'library/', forks = 1, timeout = 5, @@ -155,6 +155,21 @@ class TestPlaybook(unittest.TestCase): print data assert data.find("ears") != -1, "template success" + def test_aliased_node(self): + pb = os.path.join(self.test_dir, 'alias_playbook.yml') + actual = self._run(pb, 'test/alias_hosts') + expected = { + "alias-node.example.com": { + "changed": 3, + "failures": 0, + "ok": 4, + "skipped": 1, + "unreachable": 0, + } + } + + assert utils.jsonify(expected, format=True) == utils.jsonify(actual, format=True) + def test_playbook_vars(self): test_callbacks = TestCallbacks() playbook = ansible.playbook.PlayBook( diff --git a/test/alias_hosts b/test/alias_hosts new file mode 100644 index 0000000000..1b8081a2bb --- /dev/null +++ b/test/alias_hosts @@ -0,0 +1,2 @@ +[aliasgroup] +alias-node.example.com ansible_ssh_host=localhost ansible_ssh_port=22 diff --git a/test/alias_playbook.yml b/test/alias_playbook.yml new file mode 100644 index 0000000000..c3a5e448cf --- /dev/null +++ b/test/alias_playbook.yml @@ -0,0 +1,9 @@ +--- +- hosts: all + vars: + test_file: /tmp/ansible-alias-test + tasks: + - action: command creates=$test_file touch $test_file + - action: command creates=$test_file false + - local_action: command true + - action: command removes=$test_file rm -f $test_file