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 Let me know if you have any trouble with either of these approaches, or any questions. Thanks, Greg On Friday, February 20, 2015 at 11:03:03 AM UTC-6, Nan Liu wrote: > > In Puppet 3.3.x you can query the available resource_type via: > > require 'puppet/face' > Puppet.parse_config > Puppet::Face[:resource_type,:current].find('*') > > In Puppet 3.7.x, I can't seem to get it to return any resources (and I'm > not sure the best way to pass in the puppet environment): > > > require 'puppet/face' > > > > Puppet.settings.initialize_global_settings(['--environment=development']) > > Puppet['environment'] > => "development" > > Puppet['modulepath'] > => > "/etc/puppetlabs/puppet/environments/$environment/modules:/opt/puppet/share/puppet/modules" > > Puppet::Face[:resource_type,:current].find('*') > => nil > > The command line option works, but not very useful: > > $ puppet resource_type search * > > #<Puppet::Resource::Type:0x00000002d139e8> > #<Puppet::Resource::Type:0x00000002d12840> > ... > > What's the right way to initialize the environment, and be able to get a > list of resource_type? > > Thanks, > > 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/13d3b9a8-ea44-44f3-ad5d-20304d2493ca%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.