diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index ea0e429b6b4..6ca893b51c0 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