From 1f63c477382a2439931e8e3892a75abeadcdb8c4 Mon Sep 17 00:00:00 2001 From: Jeroen Hoekx Date: Mon, 4 Jun 2012 10:15:12 +0200 Subject: [PATCH] Introduce ansible_python_interpreter variable. This allows configuration of the correct python interpreter on the managed system. --- lib/ansible/runner/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index c49abf1764..5e713e63a3 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -721,7 +721,19 @@ class Runner(object): raise errors.AnsibleFileNotFound("module not found: %s" % in_path) out_path = tmp + module - conn.put_file(in_path, out_path) + + # use the correct python interpreter for the host + host_variables = self.inventory.get_variables(conn.host) + if 'ansible_python_interpreter' in host_variables: + interpreter = host_variables['ansible_python_interpreter'] + with open(in_path) as f: + module_lines = f.readlines() + if '#!' and 'python' in module_lines[0]: + module_lines[0] = "#!%s" % interpreter + self._transfer_str(conn, tmp, module, '\n'.join(module_lines)) + else: + conn.put_file(in_path, out_path) + return out_path # *****************************************************