ruby - 厨师/红宝石术语
问题描述
我已经开始使用 Chef 并通过文档(模板:https ://docs.chef.io/resource_template.html并且在多个地方我看到以下格式,即 2 或 3 个方括号一个接一个。我没有事先Ruby 的经验,所以我不确定它是 Ruby 的东西还是与 Chef 有关系。
我们到底用那个构造实现了什么?一个基本的例子就可以了。
例如下面的内容,这些符号究竟是做什么的,因为在某些地方它已用符号声明而有些则没有。
node.default['nginx']['remote_ip_var'] = 'remote_addr'
node.default['nginx']['authorized_ips'] = ['127.0.0.1/32']
:server_options => node[:site][:matching_node][:server][:options],
:proxy_options => node[:site][:matching_node][:proxy][:options
在开始使用 Chef 之前,我浏览了“Ruby in 20 minutes”文档以获得概述,但无法获得我正在寻找的任何信息
任何帮助都会非常有帮助。
template '/etc/sudoers' do
source 'sudoers.erb'
variables(sudoers_groups: node['authorization']['sudo']['groups'],
sudoers_users: node['authorization']['sudo']['users'])
end
node.default['nginx']['remote_ip_var'] = 'remote_addr'
node.default['nginx']['authorized_ips'] = ['127.0.0.1/32']
template "#{node[:matching_node][:dir]}/sites-available/site_proxy.conf" do
source 'site_proxy.matching_node.conf.erb'
variables(
:ssl_certificate => "#{node[:matching_node][:dir]}/shared/certificates/site_proxy.crt",
:server_options => node[:site][:matching_node][:server][:options],
:proxy_options => node[:site][:matching_node][:proxy][:options]
)
end
解决方案
使用普通的 Ruby 哈希,您会更正假设x['foo']
和x[:foo]
是单独的键。然而,为简单起见,Chef 的节点属性对象将所有键转换为字符串,因此您可以平等地使用任何一种语法。我们建议(我们的 linter 工具将帮助强制执行)您使用字符串,但有些人更喜欢符号的视觉风格。
推荐阅读
- oracle - 员工供应商名称海量更新-融合采购云
- php - PHP中的MongoDB更新:在多个ID上更新一个变量(表示为变量)
- csv - 使用 VBScript 在 CSV 中查找特定类型的字符串
- sql-server - 如何使用类似查询来解决我必须从逗号分隔数据中选择值的问题
- php - 为什么没有将多个图像保存到 Laravel 5.6 中的表格中
- javascript - StandardJS linting 返回静态变量的解析错误
- angularjs - 使用 gulp 导入
- php - Codeigniter - 带有变量的 mysql 查询
- android - 如何实现@mention功能,其中用户无法通过像WhatsApp android App这样的可跨字符串移动光标
- jboss - JBOSS AS 6 管理员控制台指南