From 3a409a457c0a9cff0887c8eb31d64f2ca43e157c Mon Sep 17 00:00:00 2001 From: Felix Ingram Date: Thu, 8 Nov 2012 13:56:16 +0000 Subject: [PATCH] Add an "executable" option to the command and shell modules The option will be passed to the Popen object created and will be used to execute the command instead of the default shell. --- command | 19 +++++++++++++++++-- shell | 6 ++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/command b/command index e1b5d0c240c..322df8ce31a 100755 --- a/command +++ b/command @@ -60,6 +60,12 @@ options: version_added: "0.6" required: false default: null + executable: + description: + - change the shell used to execute the command. Should be an absolute path to the executable. + required: false + default: null + version_added: "0.9" examples: - code: "command: /sbin/shutdown -t now" description: "Example from Ansible Playbooks" @@ -81,6 +87,7 @@ def main(): shell = module.params['shell'] chdir = module.params['chdir'] + executable = module.params['executable'] args = module.params['args'] if args.strip() == '': @@ -94,7 +101,7 @@ def main(): startd = datetime.datetime.now() try: - cmd = subprocess.Popen(args, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd = subprocess.Popen(args, executable=executable, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = cmd.communicate() except (OSError, IOError), e: module.fail_json(rc=e.errno, msg=str(e), cmd=args) @@ -140,11 +147,12 @@ class CommandModule(AnsibleModule): params = {} params['chdir'] = None params['shell'] = False + params['executable'] = None if args.find("#USE_SHELL") != -1: args = args.replace("#USE_SHELL", "") params['shell'] = True - r = re.compile(r'(^|\s)(creates|removes|chdir)=(?P[\'"])?(.*?)(?(quote)(?[\'"])?(.*?)(?(quote)(?> somelog.txt" description: Execute the command in remote shell