0

I'm looking for the best solution for automating Windows server 2012r2 via Rundeck. I'm extremely familiar with Rundeck but use it for linux vms. I've searched online for this topic but havent found anything that seems reliable. Ideally, I want to start a Runeck Job that can add users in Active Directory but not sure how to approach it. I've tried using winrm but have gotten mixed results. Ironically, it will run basic powershell commands but it errors when trying to do anything with AD. Ive even tried creating a powershell script on the AD server and have Rundeck simply execute the powershell script to no avail. Hopefully someone has had success in controlling windows nodes with Rundeck. Below is the error i receive when trying to run a powershell script.

    Execution failed: 27 in project windows: [Workflow result: , step failures: {1=Dispatch failed on 1 nodes: [Windows_AD_Server: NonZeroResultCode: [WinRMPython] Result code: 1 + {dataContext=MultiDataContextImpl(map={ContextView(node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}, ContextView(step:1, node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}}, base=null)} ]}, Node failures: {Windows_AD_Server=[NonZeroResultCode: [WinRMPython] Result code: 1 + {dataContext=MultiDataContextImpl(map={ContextView(node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}, ContextView(step:1, node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}}, base=null)} ]}, status: failed]
druffin
  • 163
  • 2
  • 15
  • 2
    not familiar with rundeck but if you only get problems when using ad commands i would check if the module is loaded / available in the host session you are running the script in first. You can do this with `Get-Module -Listavailable` for all available modules and `Get-Module` for the loaded ones – Paul Oct 26 '18 at 18:30

2 Answers2

0

Firstly, PowerShell already offers a built-in way to execute jobs, with no 3rd party addons.

About Jobs Provides information about how PowerShell background jobs run a command or expression in the background without interacting with the current session.

About Remote Jobs Describes how to run background jobs on remote computers.

PowerShell Jobs Week: Remote Jobs

I've never heard of / used Rundeck as Paul points out as well, so this just be the Rundeck has particulars that need to be in play first. Yet, looking at the docs, and a quick youtube video on the topic, there are several things that must be in place for what you say here...

I've tried using winrm but have gotten mixed results.

… to work. Video - Running commands remotely using the console with WinRM/WinRS

If Rundeck is similar to SCCM or Scheduled Task, then the same approach applies. Write Your PowerShell script. have Rundeck/ScheduedTask call powershell.exe to run the script

How to execute a PowerShell script automatically using Windows task scheduler?

Also, this could very well be seen as a duplicate of this stackoverflow discussion and answer.

rundeck unable to execute powershell script with import-module

postanote
  • 15,138
  • 2
  • 14
  • 25
0

I am setting up somethin similar and have the same problem. The AD operation executes successfully, but returns exit code 1 and throw the error you mentioned. I am in the process of debugging the plugin, but it seems there is a bug within response handling.

Please check if the ad operation works although the error is thrown and please post the script block you are using to control the AD.

Edit: in meantime I was able to narrow down the issue and opened an issue with the project: github

I provisionally fixed the issue with adding the following line in winrm-session.py after line 89:

new_msg = msg

The line before is:

" error message: %s" % (e))

The line after is:

else:

If this does not solve your issue, please post your script block.

Best Tobias

Tobias
  • 33
  • 4