Allow setting run_command environment overrides for the life of an AnsibleModule
This commit is contained in:
parent
50dfd4b057
commit
d1c2d16706
1 changed files with 7 additions and 1 deletions
|
@ -516,6 +516,9 @@ class AnsibleModule(object):
|
||||||
self._debug = False
|
self._debug = False
|
||||||
self._diff = False
|
self._diff = False
|
||||||
self._verbosity = 0
|
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.aliases = {}
|
||||||
self._legal_inputs = ['_ansible_check_mode', '_ansible_no_log', '_ansible_debug', '_ansible_diff', '_ansible_verbosity']
|
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
|
# Manipulate the environ we'll send to the new process
|
||||||
old_env_vals = {}
|
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:
|
if environ_update:
|
||||||
for key, val in environ_update.items():
|
for key, val in environ_update.items():
|
||||||
old_env_vals[key] = os.environ.get(key, None)
|
old_env_vals[key] = os.environ.get(key, None)
|
||||||
|
@ -1907,7 +1914,6 @@ class AnsibleModule(object):
|
||||||
else:
|
else:
|
||||||
running = args
|
running = args
|
||||||
self.log('Executing: ' + running)
|
self.log('Executing: ' + running)
|
||||||
|
|
||||||
cmd = subprocess.Popen(args, **kwargs)
|
cmd = subprocess.Popen(args, **kwargs)
|
||||||
|
|
||||||
# the communication logic here is essentially taken from that
|
# the communication logic here is essentially taken from that
|
||||||
|
|
Loading…
Reference in a new issue