is it possible to use supports statement in if statement in chef?

前提是你 提交于 2020-01-17 04:15:09

问题


what I'm trying to do is I want to write into a file if the service is running as RUNNING and if not, as NOT RUNNING.

service 'McAfeeFramework' do
puts 'true'
only_if{ supports :status =>true}

File.write('c:\chef-repo\n1.txt','running')
puts 'false'
only_if{ supports :status =>false}
File.write('c:\chef-repo\n1.txt','not running')
end

回答1:


You are trying to use the service resource wrong.

A service resource can be used to manage a service in the system, like enabling, disabling, starting or stopping it. The guards you are using (only_if, not_if) are meant to trigger the resource action only under certain circumstances. For example, only start a service if another one is running.

For the task you want to achieve here, you should use a powershell_script resource, where you can write some real code to be executed in the provisioned node on each chef-client run, that will write the file.

=edit=

As coderanger stated, it is possible also to use a file resource for this, although you must create the logic in ruby to add content to it rather than PS.



来源:https://stackoverflow.com/questions/42482182/is-it-possible-to-use-supports-statement-in-if-statement-in-chef

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!