From 04954dbc1e9531af5406b85b7699c6950f85440c Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 8 Oct 2012 19:03:37 -0400 Subject: [PATCH] Makes ports configurable for fireball. Note port defaults really belong in the connection plugins, not runner, which can be refactored later. --- lib/ansible/runner/__init__.py | 14 +++++++++++--- lib/ansible/runner/connection.py | 6 ++++-- lib/ansible/runner/connection_plugins/fireball.py | 13 ++++++++----- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 05eb1f6cdb1..dcc30f970e6 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -100,7 +100,7 @@ class Runner(object): pattern=C.DEFAULT_PATTERN, # which hosts? ex: 'all', 'acme.example.org' remote_user=C.DEFAULT_REMOTE_USER, # ex: 'username' remote_pass=C.DEFAULT_REMOTE_PASS, # ex: 'password123' or None if using key - remote_port=C.DEFAULT_REMOTE_PORT, # if SSH on different ports + remote_port=None, # if SSH on different ports private_key_file=C.DEFAULT_PRIVATE_KEY_FILE, # if not using keys/passwords sudo_pass=C.DEFAULT_SUDO_PASS, # ex: 'password123' or None background=0, # async poll every X seconds, else 0 for non-async @@ -208,7 +208,9 @@ class Runner(object): # hack to support fireball mode if module_name == 'fireball': - args = "%s password=%s port=%s" % (args, base64.b64encode(str(utils.key_for_hostname(conn.host))), C.ZEROMQ_PORT) + args = "%s password=%s" % (args, base64.b64encode(str(utils.key_for_hostname(conn.host)))) + if 'port' not in args: + args += " port=%s" % C.ZEROMQ_PORT (remote_module_path, is_new_style) = self._copy_module(conn, tmp, module_name, args, inject) cmd = "chmod u+x %s" % remote_module_path @@ -262,7 +264,13 @@ class Runner(object): ''' executes any module one or more times ''' host_variables = self.inventory.get_variables(host) - port = host_variables.get('ansible_ssh_port', self.remote_port) + if self.transport in [ 'paramiko', 'ssh' ]: + port = host_variables.get('ansible_ssh_port', self.remote_port) + if port is None: + port = C.DEFAULT_REMOTE_PORT + else: + # fireball, local, etc + port = self.remote_port inject = {} inject.update(host_variables) diff --git a/lib/ansible/runner/connection.py b/lib/ansible/runner/connection.py index a79b952e531..1057549f1bc 100644 --- a/lib/ansible/runner/connection.py +++ b/lib/ansible/runner/connection.py @@ -35,12 +35,14 @@ class Connection(object): def __init__(self, runner): self.runner = runner - def connect(self, host, port=None): + def connect(self, host, port): conn = None transport = self.runner.transport module = modules.get(transport, None) if module is None: raise AnsibleError("unsupported connection type: %s" % transport) conn = module.Connection(self.runner, host, port) - return conn.connect() + self.active = conn.connect() + return self.active + diff --git a/lib/ansible/runner/connection_plugins/fireball.py b/lib/ansible/runner/connection_plugins/fireball.py index 7c268b7bdff..1159814bf49 100644 --- a/lib/ansible/runner/connection_plugins/fireball.py +++ b/lib/ansible/runner/connection_plugins/fireball.py @@ -31,9 +31,9 @@ except ImportError: pass class Connection(object): - ''' SSH based connections with Paramiko ''' + ''' ZeroMQ accelerated connection ''' - def __init__(self, runner, host, port=None): + def __init__(self, runner, host, port): self.runner = runner @@ -45,9 +45,12 @@ class Connection(object): self.key = utils.key_for_hostname(host) self.context = None self.socket = None - # port passed in is the SSH port, which we ignore - self.port = constants.ZEROMQ_PORT - + + if port is None: + self.port = constants.ZEROMQ_PORT + else: + self.port = port + def connect(self): ''' activates the connection object '''