1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Use re instead of shlex.split to find executable

shlex.split will strip quotes and it might not even be sh at this point.
This commit is contained in:
Daniel Hokka Zakrisson 2013-01-09 14:13:53 +01:00
parent 910667152c
commit 92ad206b84

View file

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import shlex
import re
import ansible.constants as C
from ansible import utils
@ -30,13 +30,13 @@ class ActionModule(object):
def run(self, conn, tmp, module_name, module_args, inject):
executable = None
args = []
for arg in shlex.split(module_args.encode("utf-8")):
if arg.startswith('executable='):
executable = arg.split('=', 1)[1]
else:
args.append(arg)
module_args = ' '.join(args)
# From library/command, keep in sync
r = re.compile(r'(^|\s)(executable)=(?P<quote>[\'"])?(.*?)(?(quote)(?<!\\)(?P=quote))((?<!\\)\s|$)')
for m in r.finditer(module_args):
v = m.group(4).replace("\\", "")
if m.group(2) == "executable":
executable = v
module_args = r.sub("", module_args)
return ReturnData(conn=conn,
result=self.runner._low_level_exec_command(conn, module_args, tmp, sudoable=True, executable=executable)