[Puppet Users] Writing custom package provider for tazpkg

xf mail
Fri, 27 Aug 2010 00:05:00 -0000

I know this is not a Ruby mailing list but I am completely stumped.
I''m writing a custom package provider for the tazpkg tool used in
Slitaz Linux (http://www.slitaz.org/en/). I used the dpkg and apt
package providers as templates.

The provider can install a package just fine, the problem comes when a
package is already installed and should not be installed again. It
seems my REGEX is not matching any of the installed packages in the
list and just tries to do an install again.

I know the problem must lie in the REGEX used by the self.parse_line
method as puppet always returns no matches. Please see below for
sample output from querying tazpkg and the errors puppet is throwing.
In my example I want to ensure the screen package is installed, as you
can see in the output puppet fails to match it and installs it again.

=========Puppetd Errors
=========
debug: Puppet::Type::Package::ProviderTazpkg: Executing
''/usr/bin/tazpkg list''
debug: Trying to match ''(?-mix:^(\S+) (\S+) (\S+)$)''
warning: Failed to match tazpkg list line "\n"
debug: Trying to match ''(?-mix:^(\S+) (\S+) (\S+)$)''
warning: Failed to match tazpkg list line "\e[1mList of all installed
packages\e[0m\n"
debug: Trying to match ''(?-mix:^(\S+) (\S+) (\S+)$)''
warning: Failed to match tazpkg list line
"================================================================================\n"
debug: Trying to match ''(?-mix:^(\S+) (\S+) (\S+)$)''
debug: I am parsing a line!
debug: Hash name attr
err: Could not prefetch package provider ''tazpkg'': undefined
method
`[]'' for nil:NilClass
info: Applying configuration version ''1282844329''
debug: Puppet::Type::Package::ProviderTazpkg: Executing
''/usr/bin/tazpkg list screen''
debug: Trying to match ''(?-mix:^(\S+) (\S+) (\S+)$)''
warning: Failed to match tazpkg list line "\n\e[1mInstalled packages
of category :\e[0m
screen\n================================================================================\n================================================================================\n
packages installed of category screen.\n\n"
debug: //test2/Package[screen]: Changing ensure
debug: //test2/Package[screen]: 1 change(s)
debug: Puppet::Type::Package::ProviderTazpkg: Executing
''/usr/bin/tazpkg get-install screen''
notice: //test2/Package[screen]/ensure: created


=========parse_line module
=========
    REGEX = %r{^(\S+) (\S+) (\S+)$}
    FIELDS = [:name, :ver, :ensure]

    def self.parse_line(line)
    Puppet.debug "Trying to match ''%s''" % REGEX
        if match = REGEX.match(line)
    Puppet.debug "I am parsing a line!"
            hash = {}

            FIELDS.zip(match.captures) { |field,value|
                hash[field] = value
            }

        Puppet.debug "Hash name " + hash[:name] #+ " is "
@resource[:name]

            if hash[:name] == @resource[:name]
                Puppet.debug "I matched the name!"
                hash[:ensure] = :installed
            else
                hash[:ensure] = :absent
            end
        else
            Puppet.warning "Failed to match tazpkg list line %s" %
line.inspect
            return nil
        end

        return hash
    end

=========TazPkg output
=========
Below is a sample of what the ''tazpkg list'' command outputs:

root@vnode008:~# tazpkg list
List of all installed packages
===============================================================================attr
2.4.43-1          system-tools
bash                    4.0               system-tools
screen                  4.0.3             system-tools
<...snip...>
xorg-libXrender         0.9.4             x-window
xorg-libXss             1.1.2             x-window
===============================================================================85
packages installed.



Any help anyone can offer would be greatly appreciated!

--
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