[英]Run cmd commands with open source puppet
有人可以幫我處理開源木偶嗎?
我想向 windows 客戶端提供 jar 文件,並使用命令行執行 .jar 文件。
.jar 文件實際上是作為服務運行的應用程序的更新。
我對 puppet 語言不太熟悉,但會猜想這樣來執行 jar 文件:
exec { 'jar_execution':
command => 'cmd.exe /c java -jar foo.jar',
}
這應該是清單的一部分,看起來像這樣嗎?
service { 'fooservice':
name => foo_service,
ensure => running,
enable => true,
}
file { 'foo.jar':
path => 'C:/foo/temp/foo.jar',
ensure => file,
source => "puppet:///modules/foo/foo.jar",
}
exec { 'jar_execution':
command => 'cmd.exe /c java -jar C:/foor/temp/foo.jar',
}
代理如何實際運行此命令?
架構方面的考慮很少:
archive
資源(來自archive
模塊)而不是:在模塊的.git
歷史記錄中使用.jar
的file
。.jar
不是由您的公司開發的,您可能需要使用可能帶有一些內部緩存的權威來源。before
、 after
、 require
、 notify
來確保依賴性。 我建議將二進制文件放在模塊之外,因為不應該對二進制文件進行版本控制。 無論您使用 Puppet OSS 還是 Puppet Enterprise,您可能會有另一個可以提供文件的服務,甚至您的 puppet 基礎設施也可以提供這些包,就像它提供puppet-agent
本身一樣。
archive { 'C:/foo/temp/foo.jar':
source => https://location/to/your/.jar,
}
exec { 'C:/foo/temp/foo.jar': # notice in resource name recommended to use / not \
command => 'cmd.exe /c java -jar C:/foor/temp/foo.jar',
refreshonly => true # this one executes exec only if the file was re-downloaded (maybe it's signature has changed), or the file was removed from disk and was re-downloaded.
onlyif => 'test -f C:\foo\temp\foo.jar' # or some command that guards you to not run this .jar every time you run puppet
subscribe => Archive['C:/foo/temp/foo.jar'],
notify => Service['foo_service'] # most probably you need to restart the service after you ran the .jar, otherwise you wouldn't have added in your question.
}
service { 'foo_service':
ensure => running,
enable => true,
}
我注意到在您的示例中,您不需要在執行后刪除.jar
。 如果您需要,另一個exec
命令可以刪除相同下載的文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.