From 6fa1a490378aaa0410093dea500bf6ad37950fd2 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sat, 20 Oct 2012 10:53:34 -0400 Subject: [PATCH] Fix the basic templating system such that when the template ends in '$', life continues as normal. --- lib/ansible/runner/__init__.py | 5 +---- lib/ansible/runner/connection.py | 5 ++--- lib/ansible/utils.py | 2 ++ test/TestUtils.py | 6 ++++++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index a6d03d1281b..f97037539aa 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -399,12 +399,9 @@ class Runner(object): actual_host = delegate_to try: - transport = None # use Runner setting - if delegate_to and actual_host in [ '127.0.0.1', 'localhost' ]: - transport = 'local' if actual_port is not None: actual_port = int(actual_port) - conn = self.connector.connect(actual_host, actual_port, transport=transport) + conn = self.connector.connect(actual_host, actual_port) if delegate_to: conn.delegate = host diff --git a/lib/ansible/runner/connection.py b/lib/ansible/runner/connection.py index c3d1578eb64..3f5bce3cfd0 100644 --- a/lib/ansible/runner/connection.py +++ b/lib/ansible/runner/connection.py @@ -40,13 +40,12 @@ class Connection(object): self.runner = runner self.modules = None - def connect(self, host, port, transport=None): + def connect(self, host, port): if self.modules is None: self.modules = modules.copy() self.modules.update(utils.import_plugins(os.path.join(self.runner.basedir, 'connection_plugins'))) conn = None - if transport is None: - transport = self.runner.transport + transport = self.runner.transport module = self.modules.get(transport, None) if module is None: raise AnsibleError("unsupported connection type: %s" % transport) diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index 59c0dd44b8d..a41689873c9 100644 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -246,6 +246,8 @@ def _varFind(text): if start == -1: return None var_start = start + 1 + if var_start >= len(text): + return None if text[var_start] == '{': is_complex = True brace_level = 1 diff --git a/test/TestUtils.py b/test/TestUtils.py index 6a08b21515f..5693e3ccfc9 100644 --- a/test/TestUtils.py +++ b/test/TestUtils.py @@ -19,6 +19,12 @@ class TestUtils(unittest.TestCase): assert res == 'hello world' + def test_varReplace_trailing_dollar(self): + template = '$what $who $' + vars = dict(what='hello', who='world') + res = ansible.utils.varReplace(template, vars) + assert res == 'hello world $' + def test_varReplace_multiple(self): template = '$what $who' vars = {