【问题标题】:Can't restart firewall by using Chef无法使用 Chef 重新启动防火墙
【发布时间】:2016-04-12 21:27:10
【问题描述】:

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

伯克斯文件

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

cookbook 'firewall'

site-cookbooks/ufw/recipes/default.rb

firewall 'ufw'

firewall_rule 'http' do
  port 80
end

firewall_rule 'https' do
  port 443
end

site-cookbooks/ufw/metadata.rb

depends 'firewall'

nodes/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

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

【问题讨论】:

  • 什么版本的厨师?您可以看到它显示在 chef-client 输出的顶部。
  • 另外你不应该再使用api.berkshelf.com。它与此问题无关,但请使用 supermarket.chef.io 作为您的 berks 源。
  • @coderanger 我之前使用的是12.3.0,更新为12.8.1,但错误依旧。

标签: ubuntu chef-infra firewall ufw


【解决方案1】:

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

【讨论】:

  • 我设置了action [:create],但错误仍然相同。我会使用execute method for ufw`,但这不是一个好方法。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-30
    • 2018-05-24
    • 2015-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多