【问题标题】:Chef/Ruby terminologies厨师/Ruby 术语
【发布时间】:2018-10-19 12:53:01
【问题描述】:

我已经开始使用 Chef 并通过文档(模板:https://docs.chef.io/resource_template.html 并且在多个地方我看到以下格式,即 2 或 3 个方括号一个接一个。 我之前没有 Ruby 经验,所以我不确定它是 Ruby 的东西还是与 Chef 有关系。

我们究竟用这个构造实现了什么?一个基本的例子就可以了。

例如 w.r.t 下面,这些符号究竟是做什么的,因为在某些地方它已用符号声明,而有些则没有。

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 chef-infra


    【解决方案1】:

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

    【讨论】:

    • 谢谢你,请问。让我知道下面的构造究竟是如何工作的 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] :server_options 或 node.default['nginx']['authorized_ips'] 的最终值究竟是什么 nginx 是否被分配了 'remote_addr' 或任何我可以找到更多信息的链接真的很有帮助
    • 您可以在我们的文档docs.chef.io/attributes.html 中找到更多信息。您没有提供足够的信息来了解所有这些东西的实际值是多少,这取决于太多的东西。
    猜你喜欢
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多