> [...]
Thanks for the example. Some of the other configurations I
need to manage in the future are more complicated and simi-
lar to LDIF, for example with continuation lines & Co., so I
probably take a closer look then.
For my current task Puppet::Provider::ParsedFile was suffi-
cient, though, and the resulting code is so simple that I'm
sure I'm missing something important:
| require 'puppet/provider/parsedfile'
| require 'puppet/util/filetype'
| Puppet::Type.type(:gridengine_resource).provide(:parsed, :parent => Puppet::Provider::ParsedFile, :default_target => 'default') do
| desc 'Provider for gridengine_resource.'
| commands :qconf => 'qconf'
| # Handle gridengine configuration for complex values.
| Puppet::Util::FileType.newfiletype(:gridengine_complex) do
| # TODO: target/default_target should be used to point to a
| # specific gridengine instance and default to, well, the
| # default.
| def read
| %x{qconf -sc}
| end
| def write(text)
| Tempfile.open('gridengine_resource') do |tmpfile|
| tmpfile.write(text)
| tmpfile.close
| Puppet::Util::Execution.execute(['qconf', '-Mc', tmpfile.path])
| end
| end
| end
| def self.filetype
| Puppet::Util::FileType.filetype(:gridengine_complex)
| end
| text_line :comment, :match => /^#/;
| text_line :blank, :match => /^\s*$/;
| record_line :parsed, :fields => %w{name shortcut type relop requestable consumable default urgency}
| end
That's all. Adding, removing and changing resources suc-
cessfully correspond to adding, removing and changing lines
in the configuration file that is fed from and to the pro-
gram backend.
Two issues I encountered worth mentioning:
1. Puppet is very opinionated where your source files should
be. Sources for providers need to be in
lib/puppet/provider/$type/$something.rb. If it doesn't
find this subdirectory or source files in it, it will
complain in obscure terms.
2. While the provider source is reread on every Puppet run
on the agent, the type source is read once and then
"cached" until puppetmaster is restarted. This can be
/very/ confusing if you change something in both the type
and the provider source. I ran into a similar issue some
months ago while writing a report handler, but I had for-
gotten the pain I went through then. Thankfully in Emacs
you can just add a (shell-command "service puppetmaster
restart") to after-save-hook for the affected files.
Tim