Rundeck script execution on windows without SSH

2,137 views
Skip to first unread message

Nikolas Karavias

unread,
Dec 29, 2014, 10:21:22 AM12/29/14
to rundeck...@googlegroups.com
I'm looking into using rundeck as a job orchestrator for my environments (mixed linux / Windows hosts). For linux hosts everything is ideal. However on Windows it looks like it is not possible to setup complex workflows and execute scripts since there is no file copier other than ssh. Simple command execution over winRM works fine, but this is not enough.
 Has anyone else managed to setup Rundeck for windows targets and do more than just execute standalone commands?

Jason Hensler

unread,
Jan 6, 2015, 1:33:12 PM1/6/15
to rundeck...@googlegroups.com
I'm working on the something right now as our security team doesn't want to have to manage cygwin on all of our windows vms. My current attempt is to use powershell on the windows vm to download a file from an http server running on the same box as rundeck (I think it may be possible to use the tomcat instance of rundeck when running a war file to server the files as well). I am planning to use a script execution for my file copy agent. The script I'm using will flow something like this:
1). Copy ${file-copy.file} to <websrv-root>/htdocs/tmp/${file-copy.filename}
2). execute rd-tool to call "winRM_File_copy" job in rundeck and provide an override filter, and winRMPassword option.
The rundeck job will use winRM executor to run `powershell (new-object System.Net.WebClient).DownloadFile('http://rundeck:8080/tmp/${option.Temp_File}','${option.Destination}')`
3). rm <websrv-root>/htdocs/tmp/${file-copy.filename}

I've hit a snag right off the bat that the winrm executor seems to be trying to escape the single-quotes ( ' ) twice as they end-up being sent over as ' " ' " ' (spaces added for readability, written out that is single-quote, double-quote, single-quote, double-quote, single-quote). If you run the command with powershell as the interpreter you will see ' ' ' as powershell throws out the double-quotes. I was able to run the command with double-quotes by escaping with a back-slash ( \ ) so the command is `powershell (new-object System.Net.WebClient).DownloadFile(\"http://rundeck:8080/tmp/${option.Temp_File}\",\"${option.Destination}\")` but, powershell does not consider the double-quote valid and complains it cannot find the closing ")". I was unable to escape a single-quote.

I'm trying to find work-around for the quoting issue but, I have opened https://github.com/rundeck-plugins/rundeck-winrm-plugin/issues/22. I did notice that if I don't use any variables but, just have a static command I don't have this issue. 

Mayank Desai

unread,
Jan 12, 2015, 11:00:11 AM1/12/15
to rundeck...@googlegroups.com
Agreed, I have observed the same behavior.  So the workaround I have managed to get it work is as following:

1 - Create a variable in your node configuration and provide the value, however let the value be such that it becomes a long string with no spaces (i.e. !This+is+my+Service!)
2 - Execute a job with one step which basically writes the batch file locally on the node where the job is being executed. (i.e. ECHO dir > script.bat && ECHO hostname >> script.bat....)
3 - In the previous step you can reference the variable you created in the node definition and it will pass the value to your script file, however once the value is stored in the script.bat file, you'll have to do some text manipulation for the batch file to execute successfully.

Let me know if you have more questions.

new23d

unread,
Jan 13, 2015, 11:59:21 AM1/13/15
to rundeck...@googlegroups.com
Jason,

I've managed to pull off very complex powershell and cmd powershell commands with all sorts of quoting needing to be escaped. If you can provide here a sample command, I'll be happy to have a go at it.


Cheers,
new23d

Rangsan A

unread,
Oct 1, 2015, 1:39:07 AM10/1/15
to rundeck-discuss
Hi Jason ,

I got this problem too, I'm trying your solution but a bit confuse. Could you please show more details please like the screen shot ?

on step 2 i don't know how to parse the remote host parameter to the job  "winRM_File_copy" , and is it one line command after after step 1 like "cp ${file-copy.file} to <websrv-root>/htdocs/tmp/${file-copy.filename} && rd-tool "winRM_File_copy" "

Any help i'm really appreciated . Thank you sir.

Jason Hensler

unread,
Oct 1, 2015, 12:08:20 PM10/1/15
to rundeck-discuss
I never got this solution to work, the qouting issue prevented me https://github.com/rundeck-plugins/rundeck-winrm-plugin/issues/22


The idea was not to use a filecopy step and have it call a script the script would then call another rundeck job using the rd-tool and the job would contain the powershell download command. The company I was working for at the time opted to get a rundeck pro license which gave use access to the powershell plugins with the tradeoff that we setup a new windows VM to host a rundeck windows instance.

I do have rundeck running on a raspberry pi 2 at home and I have started using it to manage the windows machines at home so, I'll pick this back up and see if I can recreate my attempt in an updated version.

Reply all
Reply to author
Forward
0 new messages