1

自定义 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 资源上下文中是否存在问题?

4

1 回答 1

1

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

于 2014-08-19T09:02:36.813 回答