【问题标题】:When I create a LWRP why is nil my global resource into the Chef resource context当我创建 LWRP 时,为什么我的全局资源在 Chef 资源上下文中为零
【发布时间】:2014-08-19 21:53:06
【问题描述】:

自定义 LWRP 的创建报告资源在 Chef 的资源上下文中为零。这是我的第一步?

action :install do
  converge_by "Installing postgresql-#{@new_resource.version}" do    
    execute "sudo apt-get install postgresql-#{@new_resource.version} #{@new_resource.options}" do
      not_if { "dpkg --get-selections | grep postgresql-#{VERSION}" }
    end
    @new_resource.updated_by_last_action(true)
  end
end

但是,我将全局变量值保存在其他局部变量中。像这样:

action :install do
  converge_by "Installing postgresql-#{@new_resource.version}" do

    VERSION = @new_resource.version
    OPTIONS = @new_resource.options
    execute "sudo apt-get install postgresql-#{VERSION} #{OPTIONS}" do
      not_if { "dpkg --get-selections | grep postgresql-#{VERSION}" }
    end
    @new_resource.updated_by_last_action(true)
  end
end

然后,问题就解决了。

Chef 资源上下文中的全局变量是否存在问题?

【问题讨论】:

  • 你不使用verify_by + updated_by_last_action

标签: chef-infra chef-solo lwrp


【解决方案1】:

我发现在 LWRP 的子资源中使用 @new_resource 是行不通的,但使用 new_resource(不带 @)可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 2012-10-07
    • 1970-01-01
    相关资源
    最近更新 更多