1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #1505 from dhozac/delegate_to-port

Use default port if ansible_ssh_port is not set for the delegated node
This commit is contained in:
Michael DeHaan 2012-11-01 04:37:03 -07:00
commit 4399d9c3cb
4 changed files with 23 additions and 5 deletions

View file

@ -384,6 +384,7 @@ class Runner(object):
interpreters.append(i) interpreters.append(i)
for i in interpreters: for i in interpreters:
del inject[i] del inject[i]
port = C.DEFAULT_REMOTE_PORT
try: try:
delegate_info = inject['hostvars'][delegate_to] delegate_info = inject['hostvars'][delegate_to]
actual_host = delegate_info.get('ansible_ssh_host', delegate_to) actual_host = delegate_info.get('ansible_ssh_host', delegate_to)
@ -393,6 +394,7 @@ class Runner(object):
inject[i] = delegate_info[i] inject[i] = delegate_info[i]
except errors.AnsibleError: except errors.AnsibleError:
actual_host = delegate_to actual_host = delegate_to
actual_port = port
try: try:
if actual_port is not None: if actual_port is not None:

View file

@ -160,12 +160,19 @@ class TestPlaybook(unittest.TestCase):
actual = self._run(pb, 'test/alias_hosts') actual = self._run(pb, 'test/alias_hosts')
expected = { expected = {
"alias-node.example.com": { "alias-node.example.com": {
"changed": 3, "changed": 5,
"failures": 0, "failures": 0,
"ok": 4, "ok": 6,
"skipped": 1, "skipped": 1,
"unreachable": 0, "unreachable": 0,
} },
"other-alias-node.example.com": {
"changed": 1,
"failures": 0,
"ok": 1,
"skipped": 0,
"unreachable": 1,
},
} }
assert utils.jsonify(expected, format=True) == utils.jsonify(actual, format=True) assert utils.jsonify(expected, format=True) == utils.jsonify(actual, format=True)

View file

@ -1,2 +1,4 @@
other-alias-node.example.com ansible_ssh_host=localhost ansible_ssh_port=28848
[aliasgroup] [aliasgroup]
alias-node.example.com ansible_ssh_host=localhost ansible_ssh_port=22 alias-node.example.com ansible_ssh_host=localhost

View file

@ -1,5 +1,5 @@
--- ---
- hosts: all - hosts: aliasgroup
vars: vars:
test_file: /tmp/ansible-alias-test test_file: /tmp/ansible-alias-test
tasks: tasks:
@ -7,3 +7,10 @@
- action: command creates=$test_file false - action: command creates=$test_file false
- local_action: command true - local_action: command true
- action: command removes=$test_file rm -f $test_file - action: command removes=$test_file rm -f $test_file
- hosts: all
gather_facts: False
tasks:
- action: command true
delegate_to: alias-node.example.com
- action: command true