mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-01-11 07:05:27 +01:00
Allow unsetting env vars (#7)
This commit is contained in:
parent
5b17c47723
commit
7e70deb734
2 changed files with 14 additions and 2 deletions
|
|
@ -4,6 +4,8 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.module_utils.six import text_type
|
||||
from ansible.module_utils.six.moves import shlex_quote
|
||||
from ansible.plugins.shell import ShellBase
|
||||
|
||||
DOCUMENTATION = '''
|
||||
|
|
@ -35,4 +37,8 @@ class ShellModule(ShellBase):
|
|||
_SHELL_GROUP_RIGHT = ')'
|
||||
|
||||
def env_prefix(self, **kwargs):
|
||||
return 'env %s' % super(ShellModule, self).env_prefix(**kwargs)
|
||||
ret = []
|
||||
# All the -u options must be first, so we process them first
|
||||
ret += ['-u %s' % k for k, v in kwargs.items() if v is None]
|
||||
ret += ['%s=%s' % (k, shlex_quote(text_type(v))) for k, v in kwargs.items() if v is not None]
|
||||
return 'env %s' % ' '.join(ret)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,13 @@ class ShellModule(ShModule):
|
|||
def env_prefix(self, **kwargs):
|
||||
env = self.env.copy()
|
||||
env.update(kwargs)
|
||||
return ' '.join(['set -lx %s %s;' % (k, shlex_quote(text_type(v))) for k, v in env.items()])
|
||||
ret = []
|
||||
for k, v in kwargs.items():
|
||||
if v is None:
|
||||
ret.append('set -e %s;' % k)
|
||||
else:
|
||||
ret.append('set -lx %s %s;' % (k, shlex_quote(text_type(v))))
|
||||
return ' '.join(ret)
|
||||
|
||||
def build_module_command(self, env_string, shebang, cmd, arg_path=None):
|
||||
# don't quote the cmd if it's an empty string, because this will break pipelining mode
|
||||
|
|
|
|||
Loading…
Reference in a new issue