Powershellスクリプトへのパスを指定する代わりに、Puppet exec
リソースを使用して直接Powershellコマンドを実行しようとしています。Puppet execリソースを使用してPowerShellコマンドを直接実行する
exec { "Change status and start-up of Win service":
command => 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -NoLogo -NonInteractive -Command "& {set-service Spooler -Status Running -StartupType Automatic; exit (1 - [int]$?)}"',
onlyif => "if(Get-Service Spooler) { exit 0 } else { exit 1 }",
logoutput => 'on_failure',
}
私は上記のコマンドを実行しようとすると、私は次のエラーを取得する:
Error: Failed to apply catalog: Parameter onlyif failed on Exec[Change status and start-up of Win service]: 'if(Get-Service Spooler
) { exit 0 } else { exit 1 }' is not qualified and no path was specified. Please qualify the command or specify a path. at /etc/puppetlabs/code/environments/production/modules/common/manifests/svc_auto_running.pp:17
は、いくつかのリンクを見て、すべてのバイナリへのフルパスを指定して述べたように、この場合に私はがあると思いいますPS実行ファイルへのパスで、すでに指定されています。
ご協力いただければ幸いです。
UPDATE:powershellコマンドでonlyif
文をラップしようとしたところ、execを使ってpowershellコマンドを直接実行することができました。しかし、今問題は、存在しない Winサービスがonlyif
ステートメントにあるかどうかを調べると、コマンドはまだ正常にを渡すことになります。
$powershell = 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NoLogo -NonInteractive'
exec { "Change status and start-up of Win service":
command => "$powershell -Command '& {set-service iDoNotExist -Status Running -StartupType Automatic; exit (1 - [int]$?)}'",
#onlyif => "$powershell -Command '& {if(Get-Service iDoNotExist); exit (1 - [int]$?)}'",
onlyif => "$powershell -Command '& {if(Get-Service iDoNotExist) { exit 0 } else { exit 1 }}'",
logoutput => 'on_failure',
}
をあなたはおそらくもPowerShellコマンドで 'onlyif'文をラップする必要があり、私は実行可能ファイルを実行しようとしている現時点では推測します。 – arco444
ありがとう@ arco444!それはうまくいった。 :)あなたは答えとしてそれを掲示するかもしれません。私はこれを閉じます。ところで、これには私が雇うことのできるよりよい代替手段がありますか? – Technext
別の問題がありましたが、やはり立ち往生しました。私のポストを更新しました。 – Technext