我正在寻找一些红宝石的帮助。我有这个代码块来检查我的NGIX服务器是否正在侦听特定端口,如果没有,则使用Chef模板进行更改并重新启动服务器。我在这里的问题是我无法正确使用另一个Ruby块中的模板块语法。
我可以请一点语法帮助吗?
谢谢:)
ruby_block "check sayc" do
block do
server = node['fqdn']
port = puts global_ssl_port.to_i
begin
Timeout.timeout(5) do
Socket.tcp(server, port){}
end
Chef::Log.info 'connections open'
rescue
Chef::Log.fatal 'connections refused'
#Configures Server NGIX Port
template '/etc/opscode/server.rb' do
source 'server.erb'
mode '0755'
owner 'root'
group 'root'
#Add new NGIX port configuration
variables(non_ssl_port: global_non_ssl_port, ssl_port: global_ssl_port)
end
end
end
end
答案 0 :(得分:1)
如果您仍然在ruby块中,则可以使用import { Entity, EntityAspect } from "breeze-client";
export abstract class EntityBase implements Entity {
public static initializer(entity: EntityBase): void {
const entityAspect: EntityAspect = entity.entityAspect;
entityAspect.propertyChanged.subscribe(EntityBase.propertyChangedHandler);
entityAspect.validationErrorsChanged.subscribe(EntityBase.validationErrorHandler);
}
}
export class Contact extends EntityBase {
/// [Initializer]
public static initializer(entity: EntityBase): void {
super.initializer(entity);
(entity as Contact).addresses.arrayChanged.subscribe(Contact.addressesChangedHandler);
}
/// </code>
// Generated code. Do not place code below this line.
public addresses: Address[];
}
// Somewhere where MetadataStore is initialized.
metadataStore.registerEntityTypeCtor("Contact", Contact, Contact.initializer);
的新实例替换template
DSL并在此之后设置类属性 - Chef::Resource::Template.new('nginx config')
,source
和等
以下是使mode
正常运行
Chef::Resource::Template
例如,您需要在ruby_block 'create template' do
block do
r = Chef::Resource::Template.new('template_name', run_context)
r.path '/tmp/file.txt'
r.source 'file.erb'
r.cookbook 'cookbook_name'
r.mode 00600
r.run_action :create
end
end
中设置file.erb
,并且需要将templates/default/file.erb
替换为您的食谱。
答案 1 :(得分:0)
这不是厨师的工作方式。你在模板中放置了你想要的配置文件,如果配置已经过时,Chef会更新它。
更直接的问题是:您无法在ruby_block
资源中使用Chef recipe DSL。顾名思义,它只允许普通的Ruby代码。如果你想做这样的事情,你必须把它变成一个自定义资源。但是,再一次,可能不会:)