Custom Types and Providers

66 views
Skip to first unread message

Michael Legleux

unread,
Jul 10, 2014, 8:43:12 PM7/10/14
to puppet...@googlegroups.com
Using puppet 3.62

Trying to follow along with the book
At one point (beginning of ch. 3), it says using irb:

>> require 'puppet'
>> Puppet::Type.type(:package)
=> Puppet::Type::Package
My output is identical
However the next bit diverges...

>> require 'puppet'
>> Puppet.parse_config
>> Puppet::Type.type(:custom_package).provide(:apt)
=> Puppet::Type::Custom_package::ProviderApt

Puppet.parse_config returns "notice"
and
Puppet::Type.type(:custom_package).provide(:apt)  does not return Puppet::Type::Custom_package::ProviderApt as Puppet::Type.type(:custom_package) is returning nil.

my tree is identical to the books (save for the rpm and yum providers)
.
└── lib
    └── puppet
        ├── provider
        │   └── custom_package
        │       └── apt.rb
        └── type
            └── custom_package.rb

Is this book still 100% relevant or are parts achieving obsolescence?

Dan Bode

unread,
Jul 10, 2014, 8:52:45 PM7/10/14
to public puppet users
My best guess is that modulepath is not configured to the correct location.

After you run parse_config, see what Puppet[:modulepath] returns (it needs to maps to the path that contains the directory with your lib dir in it).
    ie: <module_path>/fake_module/lib

parse_config should load the default settings for Puppet which is either /etc/puppet/modules or whatever you set in puppet.conf




--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/00ab0833-4bd1-4939-a710-6223eb7e122b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Legleux

unread,
Jul 10, 2014, 9:24:16 PM7/10/14
to puppet...@googlegroups.com
Puppet[:modulepath] returns:
=> "/etc/puppet/modules:/usr/share/puppet/modules"
The tree I posted previously is located in /etc/puppet/modules/example (as the book had laid out.)
The module path must be correct (as I explain in a bit) since i see it all referenced when I run puppet on the agent I put my test class on.
Also, calling (on the master)
puppet resource custom_package 'foo' ensure=present --debug 
also seems to work just fine, I'm just seeing a disconnect between irb.
Irb seeing my modules would definitely accelerate my puppet learning.

I took what little i learned so far and tried to make a provider for a simple type. The provider has "exists?", "create" and" destroy" defined (but create and destroy are blank).
In the provider called  powershell.rb i used commands as: commands :posh => 'powershell' 
then in exists? i called:
posh('Test-Path', resource[:local])

When i run puppet agent -t --debug on the agent
I see that puppet is executing my command and "resource[:local]" is corrected interpreted to what I put in the class definition, but I don't see the output of the command during the run.
How can make sure that output gets logged somehow? The command definitely should return true or false

I hope I made myself clear and aren't digressing.

Rob Reynolds

unread,
Jul 11, 2014, 12:29:47 PM7/11/14
to puppet...@googlegroups.com
On Thu, Jul 10, 2014 at 7:43 PM, Michael Legleux <leg...@gmail.com> wrote:
Using puppet 3.62

Trying to follow along with the book
At one point (beginning of ch. 3), it says using irb:

>> require 'puppet'
>> Puppet::Type.type(:package)
=> Puppet::Type::Package
My output is identical
However the next bit diverges...

>> require 'puppet'
>> Puppet.parse_config
>> Puppet::Type.type(:custom_package).provide(:apt)
=> Puppet::Type::Custom_package::ProviderApt

Are you in the root of your custom module folder when you type irb? 
 

Puppet.parse_config returns "notice"
and
Puppet::Type.type(:custom_package).provide(:apt)  does not return Puppet::Type::Custom_package::ProviderApt as Puppet::Type.type(:custom_package) is returning nil.

my tree is identical to the books (save for the rpm and yum providers)
.
└── lib
    └── puppet
        ├── provider
        │   └── custom_package
        │       └── apt.rb

Ensure your namespace is correct for the apt.rb file. 

 
        └── type
            └── custom_package.rb

Is this book still 100% relevant or are parts achieving obsolescence?

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/00ab0833-4bd1-4939-a710-6223eb7e122b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Rob Reynolds
Developer, Puppet Labs

Join us at PuppetConf 2014September 20-24 in San Francisco
Register by July 31st to take advantage of the Early Bird discount save $249!

Michael Legleux

unread,
Jul 11, 2014, 3:26:07 PM7/11/14
to puppet...@googlegroups.com
I tried starting irb from various places along that tree and as my user and root.

The /etc/puppet/modules/example/lib/puppet/provider/custom_package/apt.rb file contains:
Puppet::Type.type(:custom_package).provide(:apt) do
  def exists?
  end
  def create
  end
  def destroy
  end
  end
end
Reply all
Reply to author
Forward
0 new messages