问题
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