Clint Savage
2009-Oct-19 20:11 UTC
[Puppet Users] Parser error which appears to be a bug in puppet
Below I have a parser function that I have created which was working, but now is not working. I have made quite a few changes to this code, but can''t seem to find the right combination to make it work again. After extensive conversations with Volcane, joe-mac and andrewcshafer from #puppet, it was suggested that I put this on the list. I don''t know what exactly is going on, but I can say that I think this is a bug now. However, I can''t prove it beyond what I have here without help. I''d like to put this out to the puppeteers here and see if I can get some more help identifying why I get the error at the end of the information below. Thanks in advance for all the help. Cheers, Clint ------------------------- ## modules/core/plugins/puppet/parser/functions/get_ad_uids.rb require ''ldap'' # this function queries our Active Directory server and pulls users with a uid greater than 50000. # Specifically used for guaranteeing homedirs exist for users in the list module Puppet::Parser::Functions newfunction(:get_ad_uids, :type => :rvalue) do |args| host = ''ad.xyz123.net'' port = LDAP::LDAP_PORT # cn=ldap,ou=System Accounts,ou=Resources,dc=ad,dc=xyz123,dc=net root = ''cn=ldap,ou=System Accounts,ou=Resources,dc=ad,dc=xyz123,dc=net'' base = ''ou=Engineering,ou=xyz123,dc=ad,dc=xyz123,dc=net'' password = ''password'' conn = LDAP::Conn.new(host, port) conn.set_option( LDAP::LDAP_OPT_PROTOCOL_VERSION, 3 ) conn.bind(root, password) uidnum = args[0] ad_uids = Array.new ids = conn.search2(base, LDAP::LDAP_SCOPE_SUBTREE, "(uidNumber>=#{uidnum})", "uid") uids = ad_uids.map { |i| i[0] }.flatten uids end end -- output of above code -- [root@tuatara (puppetmaster) functions]# irb -r puppet -r get_ad_uids.rb irb(main):001:0> Puppet::Parser::Functions::function(:get_ad_uids) => "function_get_ad_uids" irb(main):002:0> s = Puppet::Parser::Scope.new => #<Puppet::Parser::Scope:0x2adf763d7220 @namespaces=[""], @symtable={}, @defaults={}, @tags=[]> irb(main):003:0> s.function_get_ad_uids(''50000'') => ["user1", "user2", "user3", "user4"] ## manifests/templates.pp node common { include core .. snip .. } .. snip .. node puppetmaster inherits common { include puppet::server include homedir::creator $uids = get_ad_uids(''50000'') # should return an array of homedirs to ensure are created print { $uids: } # make sure the home directories exist for all ad users above # the specified uid ensure_homedirs { $uids: } .. snip .. } ==> puppet-err.log <=2009-10-19T14:02:25-06:00 tuatara puppetmasterd[4479]: Puppet::Parser::AST::Resource failed with error ArgumentError: Resources require a type and title at /var/lib/puppet/manifests/templates.pp:34 on node tuatara 2009-10-19T14:02:25-06:00 tuatara puppetmasterd[4479]: Puppet::Parser::AST::Resource failed with error ArgumentError: Resources require a type and title at /var/lib/puppet/manifests/templates.pp:34 on node tuatara 2009-10-19T14:02:25-06:00 tuatara puppetd[4538]: Could not retrieve catalog: Puppet::Parser::AST::Resource failed with error ArgumentError: Resources require a type and title at /var/lib/puppet/manifests/templates.pp:34 on node tuatara --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Clint Savage
2009-Oct-19 20:13 UTC
[Puppet Users] Re: Parser error which appears to be a bug in puppet
On Mon, Oct 19, 2009 at 2:11 PM, Clint Savage <herlo1@gmail.com> wrote:> Below I have a parser function that I have created which was working, > but now is not working. I have made quite a few changes to this code, > but can''t seem to find the right combination to make it work again. > > After extensive conversations with Volcane, joe-mac and andrewcshafer > from #puppet, it was suggested that I put this on the list. I don''t > know what exactly is going on, but I can say that I think this is a > bug now. However, I can''t prove it beyond what I have here without > help. > > I''d like to put this out to the puppeteers here and see if I can get > some more help identifying why I get the error at the end of the > information below. > > Thanks in advance for all the help. > > Cheers, > > Clint > > ------------------------- > > ## modules/core/plugins/puppet/parser/functions/get_ad_uids.rb > > require ''ldap'' > > # this function queries our Active Directory server and pulls users > with a uid greater than 50000. > # Specifically used for guaranteeing homedirs exist for users in the list > > module Puppet::Parser::Functions > newfunction(:get_ad_uids, :type => :rvalue) do |args| > > host = ''ad.xyz123.net'' > port = LDAP::LDAP_PORT > > # cn=ldap,ou=System Accounts,ou=Resources,dc=ad,dc=xyz123,dc=net > root = ''cn=ldap,ou=System Accounts,ou=Resources,dc=ad,dc=xyz123,dc=net'' > base = ''ou=Engineering,ou=xyz123,dc=ad,dc=xyz123,dc=net'' > password = ''password'' > > conn = LDAP::Conn.new(host, port) > conn.set_option( LDAP::LDAP_OPT_PROTOCOL_VERSION, 3 ) > conn.bind(root, password) > > uidnum = args[0] > ad_uids = Array.new > ids = conn.search2(base, LDAP::LDAP_SCOPE_SUBTREE, > "(uidNumber>=#{uidnum})", "uid") > uids = ad_uids.map { |i| i[0] }.flatten > > uids > > end > end > > -- output of above code -- > > [root@tuatara (puppetmaster) functions]# irb -r puppet -r get_ad_uids.rb > irb(main):001:0> Puppet::Parser::Functions::function(:get_ad_uids) > => "function_get_ad_uids" > irb(main):002:0> s = Puppet::Parser::Scope.new > => #<Puppet::Parser::Scope:0x2adf763d7220 @namespaces=[""], > @symtable={}, @defaults={}, @tags=[]> > irb(main):003:0> s.function_get_ad_uids(''50000'') > => ["user1", "user2", "user3", "user4"] > > ## manifests/templates.pp > > node common { > include core > .. snip .. > } > > .. snip .. > > node puppetmaster inherits common { > include puppet::server > include homedir::creator > > $uids = get_ad_uids(''50000'') # should return an array of homedirs > to ensure are created > print { $uids: } > # make sure the home directories exist for all ad users above > # the specified uid > > ensure_homedirs { $uids: } > > .. snip .. > } > > ==> puppet-err.log <=> 2009-10-19T14:02:25-06:00 tuatara puppetmasterd[4479]: > Puppet::Parser::AST::Resource failed with error ArgumentError: > Resources require a type and title at > /var/lib/puppet/manifests/templates.pp:34 on node tuatara > 2009-10-19T14:02:25-06:00 tuatara puppetmasterd[4479]: > Puppet::Parser::AST::Resource failed with error ArgumentError: > Resources require a type and title at > /var/lib/puppet/manifests/templates.pp:34 on node tuatara > 2009-10-19T14:02:25-06:00 tuatara puppetd[4538]: Could not retrieve > catalog: Puppet::Parser::AST::Resource failed with error > ArgumentError: Resources require a type and title at > /var/lib/puppet/manifests/templates.pp:34 on node tuatara >I should mention that line 34 is the print command above. However, if I remove that, it errors at the ''ensure_homedirs function. Clint --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Clint Savage
2009-Oct-19 22:32 UTC
[Puppet Users] Re: Parser error which appears to be a bug in puppet
On Mon, Oct 19, 2009 at 2:13 PM, Clint Savage <herlo1@gmail.com> wrote:> On Mon, Oct 19, 2009 at 2:11 PM, Clint Savage <herlo1@gmail.com> wrote: >> Below I have a parser function that I have created which was working, >> but now is not working. I have made quite a few changes to this code, >> but can''t seem to find the right combination to make it work again. >> >> After extensive conversations with Volcane, joe-mac and andrewcshafer >> from #puppet, it was suggested that I put this on the list. I don''t >> know what exactly is going on, but I can say that I think this is a >> bug now. However, I can''t prove it beyond what I have here without >> help. >> >> I''d like to put this out to the puppeteers here and see if I can get >> some more help identifying why I get the error at the end of the >> information below. >> >> Thanks in advance for all the help. >> >> Cheers, >> >> Clint >> >> ------------------------- >> >> ## modules/core/plugins/puppet/parser/functions/get_ad_uids.rb >> >> require ''ldap'' >> >> # this function queries our Active Directory server and pulls users >> with a uid greater than 50000. >> # Specifically used for guaranteeing homedirs exist for users in the list >> >> module Puppet::Parser::Functions >> newfunction(:get_ad_uids, :type => :rvalue) do |args| >> >> host = ''ad.xyz123.net'' >> port = LDAP::LDAP_PORT >> >> # cn=ldap,ou=System Accounts,ou=Resources,dc=ad,dc=xyz123,dc=net >> root = ''cn=ldap,ou=System Accounts,ou=Resources,dc=ad,dc=xyz123,dc=net'' >> base = ''ou=Engineering,ou=xyz123,dc=ad,dc=xyz123,dc=net'' >> password = ''password'' >> >> conn = LDAP::Conn.new(host, port) >> conn.set_option( LDAP::LDAP_OPT_PROTOCOL_VERSION, 3 ) >> conn.bind(root, password) >> >> uidnum = args[0] >> ad_uids = Array.new >> ids = conn.search2(base, LDAP::LDAP_SCOPE_SUBTREE, >> "(uidNumber>=#{uidnum})", "uid") >> uids = ad_uids.map { |i| i[0] }.flatten >> >> uids >> >> end >> end >> >> -- output of above code -- >> >> [root@tuatara (puppetmaster) functions]# irb -r puppet -r get_ad_uids.rb >> irb(main):001:0> Puppet::Parser::Functions::function(:get_ad_uids) >> => "function_get_ad_uids" >> irb(main):002:0> s = Puppet::Parser::Scope.new >> => #<Puppet::Parser::Scope:0x2adf763d7220 @namespaces=[""], >> @symtable={}, @defaults={}, @tags=[]> >> irb(main):003:0> s.function_get_ad_uids(''50000'') >> => ["user1", "user2", "user3", "user4"] >> >> ## manifests/templates.pp >> >> node common { >> include core >> .. snip .. >> } >> >> .. snip .. >> >> node puppetmaster inherits common { >> include puppet::server >> include homedir::creator >> >> $uids = get_ad_uids(''50000'') # should return an array of homedirs >> to ensure are created >> print { $uids: } >> # make sure the home directories exist for all ad users above >> # the specified uid >> >> ensure_homedirs { $uids: } >> >> .. snip .. >> } >> >> ==> puppet-err.log <=>> 2009-10-19T14:02:25-06:00 tuatara puppetmasterd[4479]: >> Puppet::Parser::AST::Resource failed with error ArgumentError: >> Resources require a type and title at >> /var/lib/puppet/manifests/templates.pp:34 on node tuatara >> 2009-10-19T14:02:25-06:00 tuatara puppetmasterd[4479]: >> Puppet::Parser::AST::Resource failed with error ArgumentError: >> Resources require a type and title at >> /var/lib/puppet/manifests/templates.pp:34 on node tuatara >> 2009-10-19T14:02:25-06:00 tuatara puppetd[4538]: Could not retrieve >> catalog: Puppet::Parser::AST::Resource failed with error >> ArgumentError: Resources require a type and title at >> /var/lib/puppet/manifests/templates.pp:34 on node tuatara >> > > I should mention that line 34 is the print command above. However, if > I remove that, it errors at the ''ensure_homedirs function. > > Clint >Following up the previous two messages. Thanks to everyone who helped me. Here''s the resolution (I''ve removed convos that aren''t relevant to this discussion) 15:46 < herlo> okay, so I know I just posted this on the puppet mailing list, but I was thinking a bit more about it and had a question. 15:47 < herlo> http://snipurl.com/slqcz 15:47 < herlo> my question is about how plugins return values to puppet. 15:48 < herlo> because it seems that while my function returns values, somehow puppet is not getting the values back. 15:48 < herlo> Thoughts? 15:49 < Volcane> herlo: do you have :type => :rvalue ? 15:50 < jrojas_> Volcane: yes 15:50 < jrojas_> newfunction(:get_ad_uids, :type => :rvalue) do |args| 15:50 < jrojas_> sorry i was looking at it when you asked :P 15:50 < Volcane> :) 15:50 < herlo> Volcane: right at the top of that function, or should be 15:51 < herlo> Volcane: it''s in the snipurl 15:51 < herlo> I agree it *should* return, but it is not returnning anything 16:02 < herlo> jrojas_: Volcane: any other thoughts? 16:03 < Volcane> herlo: if you rip out all the code and just return an array of known values, does it work? 16:03 < herlo> dunno. I do know that from the other direction if I put $uids = ["user1", "user2"] it works 16:04 < herlo> I''ll try that now Volcane thanx 16:06 < herlo> Volcane: hrm, that seemed to work... 16:06 < herlo> but that is really odd... 16:08 < Volcane> add to your function something like: http://pastie.org/661238 16:09 < Volcane> will write a yaml dump of what you''re returning 16:09 < Volcane> add it just before returning to puppet 16:09 < Volcane> then u can see what you''re returning 16:09 < herlo> kk 16:09 < herlo> this is leading me down a much better path 16:15 < herlo> Volcane: I get a list of users in the YAML file 16:15 < Volcane> show it 16:16 < herlo> but one is missing, wonder if that matters... 16:16 < herlo> k, hang on... 16:16 < herlo> Volcane: http://fpaste.org/EnvS/ 16:17 < Volcane> looks just fine 16:17 < herlo> yeah, I knw 16:17 < herlo> so here''s a question, one line is blank. Think that could cause problems? 16:17 < herlo> http://fpaste.org/ijUE/ 16:18 < herlo> Volcane: ^^ 16:18 < Volcane> could be 16:18 < herlo> how would you remove blanks from an array? 16:18 < Volcane> yeah i think so 16:18 < Volcane> well i guess its a nil in there? 16:18 < herlo> dunno 16:19 < herlo> it could be just '''' 16:19 < herlo> I see compact and delete_if 16:19 < herlo> I''ll dig around on that... 16:19 < herlo> thanks for the help again 16:19 < jrojas_> i[0] unless i[0].is_nil? or whatever 16:19 < herlo> jrojas_: k, I''ll check that out too 16:21 < herlo> if nothing else, I am learning alot about the insides of puppet 16:21 < jrojas_> and some ruby as well 16:21 < herlo> w000!!!!!!!!!! it works!!! 16:22 < herlo> uids = ad_uids.compact.flatten <-- that did it 16:22 < herlo> stupid nil 16:22 < jrojas_> heheh 16:22 < Volcane> herlo: :) 16:23 < herlo> I know now that it was the guys who manage the AD servers that broke it and I am going to yell their heads off 16:23 < herlo> thanks you guys.... 16:23 * herlo will update his post... 16:23 < Volcane> herlo: u can also do stuff like array.select{|el| el > 10} 16:23 < Volcane> and that''ll make an array of all elements > 10 16:24 < herlo> right, I was looking at the array syntax too. I still might need to do one for '''' and nil 16:24 < kjetilho> herlo: you want flatten.compact, I think 16:24 < kjetilho> herlo: [[nil],1,2].compact.flatten => [nil, 1, 2] 16:25 < herlo> kjetilho: yeah, but you example is wrong 16:25 < herlo> well, maybe not 16:26 < herlo> I see what you are saying 16:26 < herlo> I''ll switch that 16:26 < kjetilho> I use the [userparam].flatten.each idiom a lot, since it allows the user to pass a single value or an array 16:26 < herlo> I will check that and make sure ... 16:26 < herlo> thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---