From e0f0e8c02345da77e2d32d1128768357c920afc7 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. --- library/command | 19 +++++++++++++++++-- library/shell | 6 ++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/library/command b/library/command index e1b5d0c240c..322df8ce31a 100755 --- a/library/command +++ b/library/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