语法错误,意外的tASSOC,期待$ end

时间:2014-09-16 17:49:24

标签: chef

我已将以下代码段添加到我的production.rb环境文件中:

default_attributes (
  "chef_client" => {
    "interval" => 300
  }
)

尝试将其上传到Chef服务器时,我得到以下信息:

knife environment from file production.rb


ERROR: SyntaxError: C:/Chef/PROD/chef-starter/chef-repo/environments/production.rb:9: syntax error, unexpected tASSOC, expecting ')'
    "chef_client" => {
                    ^


C:/Chef/PROD/chef-starter/chef-repo/environments/production.rb:10: syntax error, unexpected tASSOC, expecting $end
            "interval" => 300
                         ^

1 个答案:

答案 0 :(得分:1)

您需要删除default_attributes(之间的空格。

default_attributes(
  "chef_client" => {
    "interval" => 300
  }
)

这是因为当你有空格时,Ruby不会将它解析为方法调用:

>> f ('a' => 1)
SyntaxError: (irb):4: syntax error, unexpected =>, expecting ')'
f ('a' => 1)
         ^
    from /Users/coderanger/.rbenv/versions/2.1.2/bin/irb:11:in `<main>'
>> f('a' => 1)
=> [{"a"=>1}]