Ok I've run into one more issue I could use help with on this code. It 
works fine when I'm running Puppet through Unicorn.. but when I run puppet 
locally on our puppet servers via 'puppet apply', it fails with an import 
error:

Error: Import loop detected at 
/mnt/puppet/master/puppet-base/modules/nodes/node_puppet/manifests/test.pp:15 
on node test-puppet-uswest2
Wrapped exception:
Import loop detected
Error: Import loop detected at 
/mnt/puppet/master/puppet-base/modules/nodes/node_puppet/manifests/test.pp:15 
on node test-puppet-uswest2

The line that is erroring out is this:

>     parser = 
Puppet::Parser::Parser.new(Puppet::Node::Environment.new(Puppet[:environment])) 

I've confirmed that its really the Puppet::Parser::Parser.new() function 
thats causing the issue. So obviously that probably means there is already 
a parser object somewhere... and that it does not like to be created 
multiple times. The question I've got is how can I change this line to 
reference an already existing Parser object?

On Friday, February 22, 2013 12:26:59 PM UTC-8, Matt W wrote:
>
> Thanks... I ended up with this: 
>
> > # 
> > # my_puppet_doc.rb 
> > # 
> > 
> > require 'puppet/util/rdoc' 
> > 
> > module Puppet::Parser::Functions 
> >   newfunction(:my_puppet_doc, :type => :rvalue, :doc => <<-EOS 
> > 
> > This function returns the 'puppet doc' header from the module 
> > that called it. Usage: 
> > 
> > $doc = my_puppet_doc() 
> > 
> >   EOS 
> >   ) do |args| 
> >     # Get the filename of the manifest that called us 
> >     f = source.file 
> > 
> >     # Create a Puppet file parser object 
> >     parser = 
> Puppet::Parser::Parser.new(Puppet::Node::Environment.new(Puppet[:environment]))
>  
>
> >     parser.file = f 
> >     ast = parser.parse 
> > 
> >     # Now, for the manifest walk through it line by line and parse it. 
> >     # (taken from Puppet::Util::RDoc.output) 
> >     astobj = [] 
> >     ast.instantiate('').each do |resource_type| 
> >       astobj << resource_type if resource_type.file == f 
> >     end 
> > 
> >     # Now, grab the @doc object and return it 
> >     # TODO: Implement some clean parsing to remove the puppet doc 
> formatting 
> >     return astobj[0].doc 
> >   end 
> > end 
>
> Its not perfect ... there are two big issues. 
>
> 1. We manually walk through the puppet  doc parsing process because the 
> Puppet::Utils::RDoc class *always* outputs to console or file, rather than 
> giving you an ability to just return the string. 
> 2. I probably want to run the doc object through a parser to strip out the 
> various control characters. 
>
> Other than that, it allows us to add docs to our node MOTD files like 
> this: 
>
> motd::add { $name: content => my_puppet_doc() } 
>
> --Matt 
>
> On Feb 22, 2013, at 10:15 AM, Ken Barber <[email protected]> wrote: 
>
> > I do this kind of thing here: 
> > 
> > 
> https://github.com/puppetlabs/puppetlabs-kwalify/blob/master/lib/puppet/parser/functions/validate_resource.rb#L24
>  
> > 
> > ken. 
> > 
> > On Fri, Feb 22, 2013 at 6:05 PM, Matt W <[email protected]> wrote: 
> >> I'm trying to create a function that I can call in a manifest like 
> this: 
> >> 
> >>  $doc = doc('apache::service') 
> >> 
> >> In the function, I want it to actually find the filename for the 
> >> 'apache::service' class... from there, I'm going to run some code that 
> will 
> >> generate the puppet-doc in text format, and then return it in a 
> variable. 
> >> Ultimately this is so that I can have nodes self-document themselves. 
> >> 
> >> Right now I'm stuck on figuring out the filename from the classname 
> though. 
> >> Anyone have any tips on this? Is there a function in the Puppet ruby 
> code 
> >> somewhere that will translate a class-name into a file path? 
> >> 
> >> -- 
> >> 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 [email protected]. 
> >> To post to this group, send email to [email protected]. 
> >> Visit this group at http://groups.google.com/group/puppet-users?hl=en. 
> >> For more options, visit https://groups.google.com/groups/opt_out. 
> >> 
> >> 
> > 
> > -- 
> > 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 [email protected]. 
> > To post to this group, send email to [email protected]. 
> > Visit this group at http://groups.google.com/group/puppet-users?hl=en. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
> > 
> > 
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to