rundeck-plugins / rundeck-winrm-plugin

UNMAINTAINED - Rundeck WinRM Node Executor plugin
Other
56 stars 28 forks source link

Is it possible to using the WinRM to change the Node IP? #31

Open herrygoon opened 9 years ago

herrygoon commented 9 years ago

I have using winRm to change the Node's IP with one job and two steps: 1.download the ps file to the node directory, "C:\" for example 2.execute the downloaded ps file. powershell -f "c:\downloadPs.ps1"

the ps file contents:

$index = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where-Object { ($_.IPAddress -eq "192.168.20.182") } | Select-object InterfaceIndex
$InterfaceName = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object { ($_.InterfaceIndex -eq $index.InterfaceIndex) } | Select -ExpandProperty NetConnectionId
Write-Output InterfaceName $InterfaceName
Invoke-Command -ScriptBlock {netsh interface ip set address $InterfaceName static 192.168.20.183 255.255.254.0 192.168.20.1 1}
exit 0

I can see the IP has changed,But the Rundeck job still in Running State and never to finish until Kill the job by hand.

if I using the ps:

$index = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where-Object { ($_.IPAddress -eq "192.168.20.183") } | Select-object InterfaceIndex
$InterfaceName = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object { ($_.InterfaceIndex -eq $index.InterfaceIndex) } | Select -ExpandProperty NetConnectionId
Write-Output InterfaceName $InterfaceName
start-job -name WinRm  -scriptblock {param($comp) netsh interface ip set address $comp static 192.168.20.182 255.255.254.0 192.168.20.1 1} -ArgumentList $InterfaceName

will cause the error:

[overthere-winrm:192.168.20.183] failed: exit code: 1
16:01:46            Failed: NonZeroResultCode: [overthere-winrm] result code: 1
16:01:46    GSP-PC  2. Command  [workflow] finishExecuteNodeStep(LeoVideo_Actor): NodeDispatch: NonZeroResultCode: [overthere-winrm] result code: 1
16:01:46            2: Workflow step finished, result: Dispatch failed on 1 nodes: [LeoVideo_Actor: NonZeroResultCode: [overthere-winrm] result code: 1]
16:01:46            [workflow] Finish step: 2,NodeDispatch
16:01:46            [workflow] Finish execution:  rundeck-workflow-node-first: [Workflow result: , step failures: {2=Dispatch failed on 1 nodes: [LeoVideo_Actor: NonZeroResultCode: [overthere-winrm] result code: 1]}, Node failures: {LeoVideo_Actor=[NonZeroResultCode: [overthere-winrm] result code: 1]}, flow control: Continue, status: failed]
16:01:46            [Workflow result: , step failures: {2=Dispatch failed on 1 nodes: [LeoVideo_Actor: NonZeroResultCode: [overthere-winrm] result code: 1]}, Node failures: {LeoVideo_Actor=[NonZeroResultCode: [overthere-winrm] result code: 1]}, flow control: Continue, status: failed]
16:01:46            Execution failed: 154: [Workflow result: , step failures: {2=Dispatch failed on 1 nodes: [LeoVideo_Actor: NonZeroResultCode: [overthere-winrm] result code: 1]}, Node failures:
vvchik commented 9 years ago

in that case you should use schedule job creation via ps with immediate start. I think it help you.

herrygoon commented 9 years ago

While I use powershell2.0 in win7. I using gcm -Module PSScheduledJob cannot find any items. Does any idea without update powershell?