如何在厨师模板中设置变量?

在官方文件中,只有一个使用选项
variable

对于模板:呼叫者必须通过 hash.

但是,对于我来说,我有一个非常简单的使用选项。 我只想在客户端配置模板文件中设置服务器名称 sensu
client.json.erb


这是模板文件:


{
"client": {
"name": "<%= @server_name %>",
"address": "<%= node.ipaddress %>",
"keepalive": {
"thresholds": {
"warning": 90,
"critical": 180
}
},
"subscriptions": [ "default" ]
}
}


这是我的首席:


server_name = "server1.example.com"

template "/etc/sensu/conf.d/client.json" do
variables/{
:server_name => server_name
}/
source "sensu-template/conf.d/client.json.erb"
end


配置文件结果:


{
"client": {
"name": "{}",
"address": "10.0.1.1",
"keepalive": {
"thresholds": {
"warning": 90,
"critical": 180
}
},
"subscriptions": [ "default" ]
}
}


如何将变量的名称传送到模板?
已邀请:

帅驴

赞同来自:

它纠正了我的问题:


template "/etc/sensu/conf.d/client.json" do
variables/
'server_name': server_name
/
source "sensu-template/conf.d/client.json.erb"
end

要回复问题请先登录注册