是否可以在厨师的if语句中使用support语句? [英] is it possible to use supports statement in if statement in chef?

查看:97
本文介绍了是否可以在厨师的if语句中使用support语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要执行的操作是,如果服务以RUNNING的方式运行,而不是以NOT RUNNING的方式运行,我想写入文件。

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


推荐答案

您正尝试使用服务资源错误。

A 服务资源可用于管理系统中的服务,例如启用,禁用,启动或停止该服务。您正在使用的防护(only_if,not_if)仅用于触发资源操作在某些情况下。例如,仅在另一个服务正在运行时才启动服务。

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.

对于要在此处完成的任务,应使用 powershell_script资源,您可以在其中编写一些实际代码,以在每次厨师客户端运行时在预配置节点中执行,该代码将写入文件

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 =

正如coderanger所说,也有可能为此,请使用 file 资源,尽管您必须在ruby中创建逻辑以向其添加内容而不是PS。

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.

这篇关于是否可以在厨师的if语句中使用support语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆