Matthias Saou
2009-Aug-26 18:17 UTC
[Puppet Users] Facter and arrays? Or puppet and converting strings to arrays?
Hi, As often with puppet, I''m trying to do something I think is "simple", yet I''m hitting a brick wall. What I want to do is have a client send back a list of members of a system group so that the server can create some template-based configuration files for a specific daemon, one per member. My problem here is that facter doesn''t seem to be able to return anything other than strings. Is that the case? Because it would be really easier for me to have it return an array of the members : This is what I''ve added : Facter.add(:techgroupmembers) do setcode do developers = Facter::Util::Resolution.exec(''getent group tech'') # Return only the member list developers[/^tech:\*:[0-9]+:(.+)$/, 1] end end This returns : "user1,user2,user3" I tried to add ".split('','')", but then I get "user1user2user3". I''ve searched quite a lot the reductivelabs websites, this group, and no one seems to have already complained about this. Am I just taking the wrong approach here? Then, my next problem is that once I get the comma separated string on the server, I don''t see how to convert that into an array I could easily use inside classes and definitions. ...Help? :-) Matthias -- Clean custom Red Hat Linux rpm packages : http://freshrpms.net/ Fedora release 10 (Cambridge) - Linux kernel 2.6.27.25-170.2.72.fc10.x86_64 Load : 0.29 1.37 4.47 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Paul Nasrat
2009-Aug-27 14:01 UTC
[Puppet Users] Re: Facter and arrays? Or puppet and converting strings to arrays?
2009/8/26 Matthias Saou <thias@spam.spam.spam.spam.spam.spam.spam.egg.and.spam.freshrpms.net>:> > Hi, > > As often with puppet, I''m trying to do something I think is "simple", > yet I''m hitting a brick wall. > > What I want to do is have a client send back a list of members of a > system group so that the server can create some template-based > configuration files for a specific daemon, one per member. > > My problem here is that facter doesn''t seem to be able to return > anything other than strings. Is that the case? Because it would be > really easier for me to have it return an array of the members :Correct currently facter is essentially a flat key value map. This is something that is on the roadmap to have richer data structures for 2.0, which will begin work after 1.6 ships.> Then, my next problem is that once I get the comma separated string on > the server, I don''t see how to convert that into an array I could > easily use inside classes and definitions. > > ...Help? :-)0.25 puppet has split as a function in the puppet language: Split a string variable into an array using the specified split regexp. Usage:: $string = ''v1.v2:v3.v4'' $array_var1 = split($string, '':'') $array_var2 = split($string, ''[.]'') $array_var3 = split($string, ''[.:]'') $array_var1 now holds the result [''v1.v2'', ''v3.v4''], while $array_var2 holds [''v1'', ''v2:v3'', ''v4''], and $array_var3 holds [''v1'', ''v2'', ''v3'', ''v4'']. Note that in the second example, we split on a string that contains a regexp meta-character (.), and that needs protection. A simple way to do that for a single character is to enclose it in square brackets.") Paul --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Matthias Saou
2009-Aug-27 15:22 UTC
[Puppet Users] Re: Facter and arrays? Or puppet and converting strings to arrays?
Paul Nasrat wrote :> > My problem here is that facter doesn''t seem to be able to return > > anything other than strings. Is that the case? Because it would be > > really easier for me to have it return an array of the members : > > Correct currently facter is essentially a flat key value map. This is > something that is on the roadmap to have richer data structures for > 2.0, which will begin work after 1.6 ships.Thanks for the explanation.> > Then, my next problem is that once I get the comma separated string on > > the server, I don''t see how to convert that into an array I could > > easily use inside classes and definitions. > > > > ...Help? :-) > > 0.25 puppet has split as a function in the puppet language: > > Split a string variable into an array using the specified split regexp.Aha, this is awesome! I''ve just had a look at the new features, and all of the new regexp possibilities are opening new horizons too. Thanks, Paul ;-) Matthias -- Clean custom Red Hat Linux rpm packages : http://freshrpms.net/ Fedora release 10 (Cambridge) - Linux kernel 2.6.27.25-170.2.72.fc10.x86_64 Load : 4.17 3.59 2.07 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---