RLP's Computing Blog

Creating A Custom Puppet Type & Provider With Best Practices

Article Info

Recent Changes

About


TODO: post the actual code

  • As a particular example, how do you describe options to your type as required or not? As far as I can tell from reading the source, the only way to have a required argument is to set a default to something that will fail your validation code.
  • Using the internal puppet file system functions; lib/puppet/file_system.rb
      defaultto 'template_path_argument_required'

      validate do |value|
        unless Puppet::Util.absolute_path?(value)
          fail Puppet::Error, _("File paths must be fully qualified, not '%{path}'") % { path: value }
        end
      end

      newparam(:force, :boolean => true, :parent => Puppet::Parameter::Boolean) do
  • the file resource has good examples, but is terribly complicated; a lot of the actual logic lives in lib/puppet/type/file.rb , but everything under lib/puppet/type/file/ is also used, as is a bunch of stuff under lib/puppet/util/ ; you’d think the stuff under lib/puppet/provider/file/ would be important, but very little of the actual type logic appears to live there.