From d1c2d16706afd5a3377c606131d768fa4b4074a9 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Sun, 7 Feb 2016 12:45:03 -0800 Subject: [PATCH] Allow setting run_command environment overrides for the life of an AnsibleModule --- lib/ansible/module_utils/basic.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index ea0e429b6b..6ca893b51c 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -516,6 +516,9 @@ class AnsibleModule(object): self._debug = False self._diff = False self._verbosity = 0 + # May be used to set modifications to the environment for any + # run_command invocation + self.run_command_environ_update = {} self.aliases = {} self._legal_inputs = ['_ansible_check_mode', '_ansible_no_log', '_ansible_debug', '_ansible_diff', '_ansible_verbosity'] @@ -1833,6 +1836,10 @@ class AnsibleModule(object): # Manipulate the environ we'll send to the new process old_env_vals = {} + # We can set this from both an attribute and per call + for key, val in self.run_command_environ_update.items(): + old_env_vals[key] = os.environ.get(key, None) + os.environ[key] = val if environ_update: for key, val in environ_update.items(): old_env_vals[key] = os.environ.get(key, None) @@ -1907,7 +1914,6 @@ class AnsibleModule(object): else: running = args self.log('Executing: ' + running) - cmd = subprocess.Popen(args, **kwargs) # the communication logic here is essentially taken from that