无法使用Chef重启防火墙

时间:2016-04-12 21:27:11

标签: ubuntu chef firewall ufw

我正在使用Chef为Ubuntu14.04编写防火墙手册。

Berksfile

source "https://api.berkshelf.com"

cookbook 'firewall'

站点食谱/ UFW /食谱/ default.rb

firewall 'ufw'

firewall_rule 'http' do
  port 80
end

firewall_rule 'https' do
  port 443
end

站点食谱/ UFW / metadata.rb

depends 'firewall'

节点/ myserver.json

{
    "run_list": [
        "firewall",
        "ufw"
    ]
}

knife solo cook myserver最终会出现这样的错误:

Recipe: firewall::default
  * firewall[default] action restart

    ================================================================================
    Error executing action `restart` on resource 'firewall[default]'
    ================================================================================

    NoMethodError
    -------------
    undefined method `include?' for :create:Symbol

    Cookbook Trace:
    ---------------
    /home/ironsand/chef-solo/cookbooks-3/firewall/libraries/provider_firewall_ufw.rb:67:in `block (2 levels) in <class:FirewallUfw>'
    /home/ironsand/chef-solo/cookbooks-3/firewall/libraries/provider_firewall_ufw.rb:66:in `each'
    /home/ironsand/chef-solo/cookbooks-3/firewall/libraries/provider_firewall_ufw.rb:66:in `block in <class:FirewallUfw>'

    Resource Declaration:
    ---------------------
    # In /home/ironsand/chef-solo/cookbooks-3/firewall/recipes/default.rb

     22: firewall 'default' do
     23:   ipv6_enabled node['firewall']['ipv6_enabled']
     24:   action :install
     25: end
     26:

    Compiled Resource:
    ------------------
    # Declared in /home/ironsand/chef-solo/cookbooks-3/firewall/recipes/default.rb:22:in `from_file'

    firewall("default") do
      action [:install]
      updated true
      retries 0
      retry_delay 2
      default_guard_interpreter :default
      declared_type :firewall
      cookbook_name :firewall
      recipe_name "default"
      ipv6_enabled true
      enabled true
      rules {"ufw"=>{}}
    end

我做错了什么?我该如何解决?

2 个答案:

答案 0 :(得分:0)

看起来像html食谱中的错误。 https://github.com/chef-cookbooks/firewall/blob/master/libraries/provider_firewall_ufw.rb#L67应该将操作转换为数组以确保安全。如果在firewall_rule`资源上设置firewall,它可能会有效。

答案 1 :(得分:0)

也许您应该从Chef超市安装食谱。了解如何在此处https://blog.chef.io/using-chef-supermarket-a-guided-tour安装。您需要保证metadata.rbPolicyfile.rb的连贯性。如果没有任何更新,请删除Policyfile.lock.json。还将include_recipe 'firewall::default' 添加到您的食谱中。