【问题标题】:Vagrant - JSON Attribute Syntax/UseVagrant - JSON 属性语法/使用
【发布时间】:2013-10-11 01:57:04
【问题描述】:

我目前正在使用 Vagrant 通过 chef_solo 食谱安装 glassfish 服务器。一切都安装正确,我可以访问服务器,但它需要我启用secure_admin才能从我的主机远程访问服务器。

问题在于我似乎无法找到或理解 Vagrant 的 JSON 语法来正确修改 secure_admin 的属性以启用。

我正在使用这本食谱:https://github.com/realityforge/chef-glassfish

在说明中解释了修改此类属性以输入如下代码:

# Create a basic domain that logs to a central graylog server
glassfish_domain "my_domain" do
  port 80
  admin_port 8103
  extra_libraries ['https://github.com/downloads/realityforge/gelf4j/gelf4j-0.9-all.jar']
  logging_properties {
    "handlers" => "java.util.logging.ConsoleHandler, gelf4j.logging.GelfHandler",
    ".level" => "INFO",
    "java.util.logging.ConsoleHandler.level" => "INFO",
    "gelf4j.logging.GelfHandler.level" => "ALL",
    "gelf4j.logging.GelfHandler.host" => 'graylog.example.org',
    "gelf4j.logging.GelfHandler.defaultFields" => '{"environment": "' + node.chef_environment + '", "facility": "MyDomain"}'
  }
end

但是,如果我想修改端口或域名等功能,我必须使用这种语法编辑这些属性(我的 vagrantfile 中已经有什么):

chef.json = {


    "glassfish" => {
         "base_dir" => "/usr/local/glassfish",
         "domains_dir" => "/usr/local/glassfish/glassfish/domains",
         "domains" => {
            "domain1" => {
               "config" => {
             "domain_name" => "domain1",
             "admin_port" => 4848,
             "username" => "root",
             "password" => "admin",
                }
            }
        }
    }

}

正如我在本食谱的“attribute_driven_domain”配方中看到的那样,这段代码对我来说很有意义,open 语句就是这样描述的。意思是编辑域的最小内存,我会输入:

"glassfish" => {
   "domains" => {
      "domain1" => {
         "config" => {
            "min_memory" => 512
         }
      }
   }
}

这个 ^ 对应于:

['glassfish']
['domains']
['config']
['min_memory']

....在食谱的这一部分中找到:

gf_sort(node['glassfish']['domains']).each_pair do |domain_key, definition|
  domain_key = domain_key.to_s

  Chef::Log.info "Defining GlassFish Domain #{domain_key}"

  admin_port = definition['config']['admin_port']
  username = definition['config']['username']
  secure = definition['config']['secure']
  password_file = username ? "#{node['glassfish']['domains_dir']}/#{domain_key}_admin_passwd" : nil
  system_username = definition['config']['system_user']
  system_group = definition['config']['system_group']

  if (definition['config']['port'] && definition['config']['port'] < 1024) || (admin_port && admin_port < 1024)
    include_recipe 'authbind'
  end

glassfish_domain domain_key do
    min_memory definition['config']['min_memory'] if definition['config']['min_memory']
    max_memory definition['config']['max_memory'] if definition['config']['max_memory']
    max_perm_size definition['config']['max_perm_size'] if definition['config']['max_perm_size']
    max_stack_size definition['config']['max_stack_size'] if definition['config']['max_stack_size']
    port definition['config']['port'] if definition['config']['port']

但是,在定义安全管理员的部分,我看不到一个明确的位置来指示它应该放置在 chef.json 块中的位置。在本节中找到:

glassfish_secure_admin "#{domain_key}: secure_admin" do
    domain_name domain_key
    admin_port admin_port if admin_port
    username username if username
    password_file password_file if password_file
    secure secure if secure
    system_user system_username if system_username
    system_group system_group if system_group
    action ('true' == definition['config']['remote_access'].to_s) ? :enable : :disable
  end

我似乎无法弄清楚 secure_admin 属性应该放在我的 vagrantfile 中的 chef.json 块中的什么位置。我尝试将其放置在不同的位置,例如 glassfish 级别下、域级别下、配置下。

我真的不知道我到底应该放什么,或者放哪里。

我一直在使用它的变体:

"secure_admin" => {
  "domain_name" => "domain1"
  "action" => :enable
}

如果它在 domain1 下但在配置之上,则像这样:

"secure_admin" => {
  "action" => :enable
}

大多数时候它不会给出任何关于更改或错误的反馈,有时如果它放在某些位置它会失败,因为它试图将它作为一个单独的域来读取,但除此之外并不多。

我当前用于修改属性的语法是否不正确?我对这些东西很新鲜,所以我真的不知道。抱歉,帖子太长了。

【问题讨论】:

    标签: json attributes glassfish vagrant chef-solo


    【解决方案1】:

    看起来要启用远程访问,您需要将 domain['config']['remote_access'] 的节点属性设置为 true。这只是基于三元运算符的猜测。所以在你原来的例子中:

    "glassfish" => {
             "base_dir" => "/usr/local/glassfish",
             "domains_dir" => "/usr/local/glassfish/glassfish/domains",
             "domains" => {
                "domain1" => {
                   "config" => {
                 "domain_name" => "domain1",
                 "admin_port" => 4848,
                 "username" => "root",
                 "password" => "admin",
                 "remote_access" => true
                    }
                }
            }
        }
    

    【讨论】:

    • 啊,我以为我在代码中遇到了这个问题。我不确定我是否曾经尝试过,但我会回到这里。谢谢!
    • 设置 ("remote_access" => true ) 有效!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-25
    相关资源
    最近更新 更多