From f16b745f172a92e0357491bd5fdfea111de50089 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 31 Jul 2015 12:01:32 -0400 Subject: [PATCH] now properly uses default port if defined --- lib/ansible/inventory/host.py | 3 +-- lib/ansible/inventory/ini.py | 2 +- lib/ansible/playbook/play_context.py | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/inventory/host.py b/lib/ansible/inventory/host.py index 2de190ce1dc..43a96d54bfb 100644 --- a/lib/ansible/inventory/host.py +++ b/lib/ansible/inventory/host.py @@ -19,7 +19,6 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from ansible import constants as C from ansible.inventory.group import Group from ansible.utils.vars import combine_vars @@ -76,7 +75,7 @@ class Host: self.ipv4_address = name self.ipv6_address = name - if port and port != C.DEFAULT_REMOTE_PORT: + if port: self.set_variable('ansible_ssh_port', int(port)) self._gathered_facts = False diff --git a/lib/ansible/inventory/ini.py b/lib/ansible/inventory/ini.py index 8d5f5f052fa..f4762bad2fd 100644 --- a/lib/ansible/inventory/ini.py +++ b/lib/ansible/inventory/ini.py @@ -108,7 +108,7 @@ class InventoryParser(object): if len(tokens) == 0: continue hostname = tokens[0] - port = C.DEFAULT_REMOTE_PORT + port = None # Three cases to check: # 0. A hostname that contains a range pesudo-code and a port # 1. A hostname that contains just a port diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index fb55c0d6a5f..e94e5d6c865 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -298,6 +298,10 @@ class PlayContext(Base): if variable_name in variables: setattr(new_info, attr, variables[variable_name]) + # make sure we get port defaults if needed + if newinfo.port is None and C.DEFAULT_REMOTE_PORT is not None: + newinfo.port = int(C.DEFAULT_REMOTE_PORT) + # become legacy updates if not new_info.become_pass: if new_info.become_method == 'sudo' and new_info.sudo_pass: