Good Afternoon/evening/morning,
I’m having a little trouble writing a custom LWRP. It’s pretty simple as I’m trying to get my head round how @current_resource works.
Here’s the code followed by the error; any ideas what I’m doing wrong? (this LWRP is contained in an library cookbook called AirWatch)
Resource:
#test lwrp
actions :create, :remove
default_action :create
#attributes to use such as path
attribute :path, :kind_of => String, :default => "c:\"
attribute :filename, :kind_of => String, :name_attribute => true
#attr_accessor :exists
Provider:
#test lwrp
#define actions
action :create do
if @current_resource.exists(true)
Chef::Log.info "#{ @new_resource } already exists, nowt to do chief"
else
resource current_resource.filename do
#copy_file
::File.new(@current_resource)
Chef::Log.info "#{ @new_resource } created"
end
end
end
action :delete do
if @current_resource.exists(true)
#delete_file
::File.delete(@current_resource)
Chef::Log.info "#{ @new_resource } has been removed"
else
Chef::Log.info "#{ @new_resource } not found, nowt to do"
end
end
#define current_resource
def load_current_resource
@current_resource = Chef::Resource::AirWatchchfile.new(new_resource)
@current_resource.path(new_resource.path)
@current_resource.filename(new_resource.filename)
@current_resource
if (::File.exist?(@current_resource)) then
Chef::Log.info “#{ @current_resource } has been found”
@current_resource.exists = true
else
Chef::Log.info “#{ @current_resource } has not been found”
@current_resource.exists = false
end
end
Recipe calling it:
include_recipe 'chef_handler’
include_recipe 'windows’
include_recipe ‘AirWatch’
#map to managment server and copy AirWatch installer to upgrade to
AirWatch_chfile ‘chtest.txt’ do
action :create
end
#perform some post upgrade tests - check port etc
#done
Error:
[cid:image001.png@01D03B1F.BF1B0B70]
Any help greatly appreaciated.
Thanks
Chris