首页 > 解决方案 > 厨师/红宝石术语

问题描述

我已经开始使用 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

标签: rubychef-infra

解决方案


使用普通的 Ruby 哈希,您会更正假设x['foo']x[:foo]是单独的键。然而,为简单起见,Chef 的节点属性对象将所有键转换为字符串,因此您可以平等地使用任何一种语法。我们建议(我们的 linter 工具将帮助强制执行)您使用字符串,但有些人更喜欢符号的视觉风格。


推荐阅读