On Thu, Feb 26, 2015 at 11:36 AM, Greg Sarjeant <gsarje...@puppetlabs.com>
wrote:

> Hi, Nan.
>
> If you're using directory environments, then you can do this in a couple
> of ways in PE 3.7.
>
> First, The Node Classifier API exposes this information. You can use the
> puppetclassify <https://github.com/puppetlabs/puppet-classify> gem to
> retrieve this information from the NC API. You can install the
> puppetclassify gem on your PE master with the vendored gem executable:
>
> /opt/puppet/bin/gem install puppetclassify
>
> Once that's installed, you can do something like this to fetch all of the
> classes in the development environment (replacing the dummy FQDN of the
> puppet master, of course).
>
> #!/opt/puppet/bin/ruby
>
> require 'puppetclassify'
>
> rest_api_url = 'https://PUPPET.MASTER.FQDN:4433/classifier-api'
>
> cert_dir  = '/opt/puppet/share/puppet-dashboard/certs'
> cert_name = 'pe-internal-dashboard'
> auth_info = {
>   'ca_certificate_path' => "#{cert_dir}/ca_cert.pem",
>   'certificate_path'    => "#{cert_dir}/#{cert_name}.cert.pem",
>   'private_key_path'    => "#{cert_dir}/#{cert_name}.private_key.pem"
> }
>
> puppetclassify = PuppetClassify.new(rest_api_url, auth_info)
>
> environment = 'development'
> puts puppetclassify.classes.get_environment_classes(environment)
>
>
> This would run on the PE Master, and use the internal console certs for
> authentication. Here is the PE 3.7 NC REST API documentation
> <https://docs.puppetlabs.com/pe/latest/nc_index.html> for reference.
>
>
> If you would like to continue using your current approach, then the search
> method of Puppet::Face[:resource_type, :current] will do a regular
> expression match. The 'find' method will instead return the first resource
> type with the specified name, which is why find('*') is returning no
> results. The search method accepts an optional hash through which you can
> specify the environment, and returns an array of Puppet::Resource::Type
> objects, which you can render as PSON and then parse to return a hash that
> you can work with. Here's a sample that does this in my PE 3.7.1 vagrant
> environment (I've created a 'dev' directory environment and installed the
> puppetlabs/ntp module there):
>
> #!/opt/puppet/bin/ruby
>
> require 'puppet/face'
> require 'json'
>
> Puppet.parse_config
>
> resources =  Puppet::Face[:resource_type, :current].search('ntp', {:extra
> => { 'environment' => 'dev' }})
>
> resources.each do |resource|
>   puts JSON.parse(resource.render('pson'))
> end
>
>
This works great. Diving a bit deeper, I'm curious what exactly process the
:extra option, because it's not obvious looking at the indirector code or
the puppet face for resource_type.

Thanks for both solutions.

Nan

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/CACqVBqAn1t31%3DRHgE_Z0p98fai2MLE_5EerJy28WCsoXhchgrQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to