[Puppet Users] Custom providers
Hi, I have a custom provider that seems to run ok in isolation by itself. In addition, puppet does not complain at all when it runs. However, when I ensure => installed a package the desired package is never installed. There are a few differences between this and something such as the gem provider, most importantly, I couldn't find anyway to get the provider to run as a different user without doing direct system call. Here's the provider Puppet::Type.type(:package).provide :npm, :parent => Puppet::Provider::Package do desc "node.js package management with npm" commands :npm_cmd => "/home/node/opt/bin/npm" raise Puppet::Error, "The npm provider can only be used as root" if Process.euid != 0 def self.npm_list(hash) begin s = `sudo -u node sh -c \"export PATH=/home/node/opt/bin:$ {PATH}; npm ls installed\"` list = s.split("\n").collect do |set| if npm_hash = npm_split(set) npm_hash[:provider] = :npm if npm_hash[:name] == hash[:justme] npm_hash else nil end else nil end end.compact rescue Puppet::ExecutionFailure => detail raise Puppet::Error, "Could not list npm packages: #{detail}" end list.shift end def self.npm_split(desc) split_desc = desc.split(/ /) installed = split_desc[0] name = installed.split(/@/)[0] version = installed.split(/@/)[1] if (name.nil? || version.nil?) Puppet.warning "Could not match #{desc}" nil else return { :name => name, :ensure => version } end end def install output = `sudo -u node sh -c \"export PATH=/home/node/opt/bin:$ {PATH}; npm install http-console\"` if output =~ /npm not ok/ raise Puppet::ExecutionFailure, "Failed to install #{resource[:name]}" end end def uninstall output = `sudo -u node sh -c \"export PATH=/home/node/opt/bin:$ {PATH}; npm uninstall #{resource[:name]}\"` if output =~ /npm not ok/ raise Puppet::ExecutionFailure, "Failed to uninstall #{resource[:name]}" end end def query version = nil self.class.npm_list(:justme => resource[:name]) end end Does anybody have an idea what's going wrong? The other problem I'm having is that I have to manually copy the provider to puppet lib from the module lib. Thanks. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@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.
[Puppet Users] Re: Custom providers
On Jan 6, 4:01 pm, pl wrote: > def install > output = `sudo -u node sh -c \"export PATH=/home/node/opt/bin:$ > {PATH}; npm install http-console\"` > if output =~ /npm not ok/ > raise Puppet::ExecutionFailure, "Failed to install > #{resource[:name]}" > end > end Note that this was a hard-coded package (http-console) I added just to see if it would install. It didn't. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@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.
[Puppet Users] Re: Custom providers
Hi, So, after setting pluginsync = true I manage to get this working, but only executing correctly as puppetd --test Except that it only functions correctly when run as puppetd --test, when I run it as the puppet service the custom provider does not do anything. This seems odd. The only notice I have in /var/log/messages is "Provider npm has not defined the 'instances' class method" Is that required? On Jan 6, 4:10 pm, pl wrote: > On Jan 6, 4:01 pm, pl wrote: > > > def install > > output = `sudo -u node sh -c \"export PATH=/home/node/opt/bin:$ > > {PATH}; npm install http-console\"` > > if output =~ /npm not ok/ > > raise Puppet::ExecutionFailure, "Failed to install > > #{resource[:name]}" > > end > > end > > Note that this was a hard-coded package (http-console) I added just to > see if it would install. It didn't. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@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.
[Puppet Users] Re: Custom providers
Hi, > Puppet::Provider::Package defines the prefetch class method. This is > called at the beginning of the puppet run to find matches between existing > packages and the one you described in your manifest. Prefetch calls > instances which should return an array of provider instances. One > provider instance for each package with the appropiate property_hash > {ensure => "whatever-version"}. If you dont know how to implement it try > with returning an empty array like hpux.rb does. Thanks. I still have this problem that I can't run puppet as a daemon and install packages as any other user. Trying to sudo inside the custom provider fails if puppet is running as a daemon. Is there no way around that? -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@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.
[Puppet Users] Re: Custom providers
Hi, > Puppet::Util::SUIDManager.asuser("username", "group") do > # do stuff here as different user > end Not sure this works how you suggested as this Puppet::Util::SUIDManager.asuser("userx", "userx") do execpipe("whoami") do |output| Will report root, not userx. I'll check the source. -- 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.
[Puppet Users] Re: Custom providers
Hi, > Can you instrument your code to > dump Process.uid and Process.gid from Ruby-space in the block? That > way we can help narrow down where things are going wrong. Process.uid was telling me 500, which was the intended user. whoami inside the execpipe was root though. I've ended up doing this def self.exec_as_user(op, pkg) Puppet::Util::SUIDManager.asuser("node", "node") do s = execute ["my", "command", "and", "args"] s.split("\n").collect do | line | yield line end end end which is doing what I want -- 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.
[Puppet Users] force backup of config files
This is the situation: We have a bunch of config files. We check if mtime changed. The line written in syslog is trapped by a monitoring tool and someone is warned. This works fine... What we want is 1. to backup the file when mtime has changed (and keep x versions) 2. execute a diff between new file and last backup and send it by mail to so. I don't see any way to do 1. If I try in the file type ... backup => puppet ... it doesn't work. The doc says it will be backed up before a change ( for ex with source => ... ) but I don't want to change it. I can do sth like: file { "test.txt": ... checksum => mtime } exec{ "myscript": ... subscribe => File["test.txt"], refreshonly => true } with script "myscript" doing a backup, a diff and send the mail, but I don't want to reinvent everything. How can I use a filebucket ? NB: these config changes are made by a automatic deploiement system, so we cannot manage it in Puppet. But we want to be warn when a change occurs to avoid "accidental" manual changes... --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---