Hi all,

I am writing a new type to handle files like sysctl.conf that are
basically name value pairs. Being new to both ruby and Puppet, I know
am doing something ridiculous.

This is the error I get:
Could not autoload "/var/lib/puppet/lib/puppet/provider/hash_config/
hash_config.rb": wrong number of arguments (0 for 1)
Could not autoload "/var/lib/puppet/lib/puppet/provider/hash_config/
hash_config.rb": wrong number of arguments (0 for 1)

class myhash {
        hash_config{"test":
#               ensure => present,
                value => "x",
                comment_character => '#',
                file => "/tmp/test_pratod",
        }

When I uncomment the ensure statement, I get
err: //myhash/Hash_config[test]: Failed to retrieve current state of
resource: No ability to determine if hash_config exists


Thanks for your help


Here is the type

Puppet::Type.newtype(:hash_config) do
    @doc = "Manage name value entries in config file. eg sysctl -
kernel.modprobe = /sbin/mod probe
        Comments and blank lines are stripped. For now the only
separator value allowed is '=' with spaces around it"

    ensurable

    newparam(:name) do
        desc "The name of the entry.  eg kernel.modprobe"
    end

    newparam(:comment_character) do
        desc "What character does the config file use for a comment.
It defaults to '#' XXXX - need to update to include ';'"

        defaultto '#'
    end

    newparam(:file) do
        desc "What configuration file to add resource to"
    end

    newparam(:value) do
        desc "The value to be set. eg /sbin/mod probe"
    end


end

______________________________________________


Here is the provider

Puppet::Type.type(:hash_config).provide do
    target_hash = Hash.new
    fetched = Boolean.new(false)
    changed = Boolean.new(false)
#
    def prefetch
        f = File.open(@resource[:file], "r")
        lines = f.readlines
        lines.each do |line|
            if line !~ /@resource[:comment_character]/
                key, target_hash[key] = line.split("=")
            end
        end
        fetched = true
    end
#
    def flush
        if changed do
            f = File.open(@resource[:file], "w")
            target_hash.keys.each do |key|
                f.puts key + " " + target_hash[key] + "\n"
            end
            end
        end
    end

#
    def create
        if not fetched
            self.prefetch
        end
        target_ha...@resource[:name]] = @resource[:value]
        changed = true
        self.flush

end
#
    def destroy
    end
#
    def exists?
        if not fetched
            self.prefetch
        end
        true
    end
#

    def retrieve
    if not fetched
      self.prefetch
    end
        if target_hash.has_key? @resource[:name]
            return target_ha...@resource[:name]]
        else
            return ''
        end
    end
    self.prefetch
    self.create
    self.flush
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to