1

The creation of a custom LWRP are reporting that the resource is nil into the Chef's resource context . This was my first step?

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

But, I save the global variable value in other local variable. Like this:

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

And then, the problem was resolved.

Is there a problem in the Chef resources context with the global variables?

Robert
  • 10,403
  • 14
  • 67
  • 117

1 Answers1

1

I found that using @new_resource in a sub resource of an LWRP just doesn't work, but using new_resource (without the @) works fine.

brasofilo
  • 25,496
  • 15
  • 91
  • 179
James Hewitt
  • 83
  • 1
  • 2