I discovered the problem. I needed pluginsync=true in the client''s /
etc/puppet.conf file
On Dec 16, 8:28 am, ccaum <carl.c...@gmail.com>
wrote:> Hello all. I''m developing a custom provider to help manage
> configuration files. The approach I''m taking allows me to easily
> treat lines as resources themselves by using markers in the file to
> show the start and end of a resource. I seem to be missing something
> since puppet does not execute the resource I''ve created. It knows
the
> resource exists though since it does not throw an error when I use the
> resource in a manifest. The module name is configfile. The resource
> I''m creating is called entry. Here''s my layout:
>
> configfile/plugins/puppet/type/entry.rb
> configfile/plugins/puppet/provider/entry/entry.rb
>
> Here''s my manifest:
>
> node test01 inherits test {
>
> entry {"My Entry":
> file => "/etc/test.conf",
> ensure => present,
> entry => "My single line",
> }
>
> }
>
> Here''s the provider entry.rb:
> Puppet::Type.type(:entry).provide do
>
> header = @resource[:comment_character] + " PUPPET: " +
@resource
> [:name]
> footer = @resource[:comment_character] + " PUPPETEND: " +
@resource
> [:name]
>
> def create
> #Open the file
> f = File.open(@resource[:file], "a")
>
> f.puts header
> f.puts @resource[:entry]
> f.puts footer
> end
>
> def destroy
> f = File.open(@resource[:file], "a")
>
> #Set start and finish to begining of file
> start = 0
> finish = 0
>
> lines = f.readlines
>
> counter = 0
> lines.each do |line|
> #Strip newline character
> line, throwaway = line.split("\n")
>
> if line == header
> start = counter
> end
>
> if line == footer
> finish = counter
> end
>
> #Incrememnt counter last so we can use zero origin
> indexing
> counter += 1
> end
>
> #Remove lines from array
> lines[start..finish] = []
>
> #Delete file and write new data
> f = File.open(@resource[:file], "w")
> f.puts lines
> end
>
> def exists?
>
> #Open the file read only
> f = File.open(@resource[:file], "r")
>
> lines = f.readlines
>
> lines.each do |line|
> #Strip newline character
> line, throwaway = line.split("\n")
>
> if line == header
> return true
> end
> end
>
> false
> end
>
> def entry
> #open the file read only
> f = File.open(@resource[:file], "r")
>
> readLine = false
> entry = []
>
> f.each do |line|
>
> #Put this before the code that reads in the line.
> # That way we don''t read in the footer
> # Purposefully don''t strip \n from line,
we''ll need it
> later
> if line == (footer + "\n")
> readLine = false
> end
>
> #Read in line
> if readLine == true
> entry.push(line)
> end
>
> #Put this after the code that reads in the line.
> # That way we don''t read in the header
> # Purposefully don''t strip \n from line,
we''ll need it
> later
> if line == (header + "\n")
> readLine = true
> end
> end
>
> #Remove last newline character since we added that
> entry[-1] = entry[-1].chomp
> #convert array to string
> entry.to_s
> end
>
> def entry=(value)
> f = File.open(@resource[:file], "a")
>
> #Set start and finish to begining of file
> start = 0
> finish = 0
>
> #split value in to an array
> value_arr = value.split("\n")
>
> lines = f.readlines
>
> counter = 0
> lines.each do |line|
> #Strip newline character
> line, throwaway = line.split("\n")
>
> if line == header
> start = counter
> end
>
> if line == (footer + "\n")
> finish = counter
> end
> end
>
> lines[start+1..finish-1] = value_arr
>
> #Empty file and write new lines
> f = File.open(@resource[:file], "a")
> f.puts lines
>
> end
> end
>
> Here''s my type entry.rb:
> Puppet::Type.newtype(:entry) do
> @doc = "Manage entry in config file."
>
> ensurable
>
> newparam(:name) do
> desc "The name of the entry. It is not recommended to use the
> entry itself for the name. The name will be used to place markers
> inside the configuration file."
> end
>
> newparam(:comment_character) do
> desc "What character does the config file use for a comment.
> It defaults to ''#''"
>
> defaultto ''#''
> end
>
> newparam(:addbefore) do
> desc "What line containing addbefore value to add entry
> before"
> end
>
> newparam(:addafter) do
> desc "What line containing addafter value to add entry after.
> Supports regular expressions."
> end
>
> newparam(:addafterlinenumber) do
> desc "What line number to add value after"
> end
>
> newparam(:file) do
> desc "What configuration file to add resource to"
> end
>
> newproperty(:entry) do
> desc "The entry to add to the config file"
> end
> end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---