I am trying to invoke a PowerShell command from Puppet. The issue is even if the PowerShell command is incorrectly supplied (in this case, iisres
instead of iisreset
), Puppet shows successful run as shown below:
Notice: /Stage[main]/Common::Iis::Iis_reset/Utils::Powershell_test[Restart IIS service]/Exec[Running command invoke-command -scriptblock {iisres} -verbose on agent]/returns: executed successfully
Few days ago, i had asked a similar question and the suggestion made in that post was working fine till i came across this issue. Here's the script:
[root@pe-server] cat iis_reset.pp
class common::iis::iis_reset {
utils::powershell_test { 'Restart IIS service':
command => 'invoke-command -scriptblock {iisres} -verbose',
}
}
[root@pe-server] powershell_test.pp
define utils::powershell_test (String $command) {
$powershell = 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NoLogo -NonInteractive'
exec { "Running command $command on agent":
command => "$powershell -Command \"& {$command; exit (1 - [int]$?)}\"",
logoutput => 'on_failure',
}
}
How to fix such issues for good?
Note: I was actually using the Powershell provider by Puppet earlier for all exec
commands until i faced this issue.