Allow setting run_command environment overrides for the life of an AnsibleModule

This commit is contained in:
Toshio Kuratomi 2016-02-07 12:45:03 -08:00
parent 50dfd4b057
commit d1c2d16706

View file

@ -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