moved to shlex.join as requested

pull/80146/head
Brian Coca 1 year ago
parent 3597bbb726
commit 36525c2755

@ -165,4 +165,4 @@ class BecomeModule(BecomeBase):
user = self.get_option('become_user') or ''
success_cmd = self._build_success_command(cmd, shell)
return ' '.join([exe, shlex.quote(flags), shlex.quote(user), '-c', shlex.quote(success_cmd)])
return shlex.join([exe, flags, user, '-c', success_cmd])

@ -95,12 +95,11 @@ class BecomeModule(BecomeBase):
if not cmd:
return cmd
becomecmd = self.get_option('become_exe') or self.name
command = [self.get_option('become_exe') or self.name]
flags = self.get_option('become_flags') or ''
prompt = ''
if self.get_option('become_pass'):
self.prompt = '[sudo via ansible, key=%s] password:' % self._id
if flags: # this could be simplified, but kept as is for now for backwards string matching
reflag = []
for flag in shlex.split(flags):
@ -110,12 +109,19 @@ class BecomeModule(BecomeBase):
# handle -XnxxX flags only
flag = re.sub(r'^(-\w*)n(\w*.*)', r'\1\2', flag)
reflag.append(flag)
flags = shlex.join(reflag)
if reflag:
command.extend(reflag)
prompt = '-p %s' % shlex.quote(self.prompt)
self.prompt = '[sudo via ansible, key=%s] password:' % self._id
command.extend(['-p', self.prompt])
elif flags:
command.append(flags)
user = self.get_option('become_user') or ''
if user:
user = '-u %s' % shlex.quote(user)
command.extend(['-u', user])
command.append(self._build_success_command(cmd, shell))
return ' '.join([becomecmd, flags, prompt, user, shlex.quote(self._build_success_command(cmd, shell))])
return shlex.join(command)

Loading…
Cancel
Save