Answering the requirement you could do something like. Facter.add("websites_number") do setcode do websites = %x{/bin/ls $websitesdir}.split("\n") 0.upto(websites - 1).each do |n| Facter.add("website_#{n}") do setcode do websites[n] end end websites.size end end
On Mon, Nov 26, 2012 at 2:48 AM, Michael Stahnke <stah...@puppetlabs.com>wrote: > On Sun, Nov 25, 2012 at 11:00 PM, Walter Heck <walterh...@gmail.com> > wrote: > > I think you might be using the wrong tool for the job, but we need a > > little bit more information to determine that: What do you want to do > > with these facts once you have them in puppet? > > > > If you are managing websites with puppet, you should probably manage > > the folders themselves with puppet, removing your need for the fact. > > > > cheers, > > > > Walter > > > > On Sun, Nov 25, 2012 at 10:16 PM, frap <l...@brig.gs> wrote: > >> I'm trying to write a custom fact for Puppet, but I have next to no Ruby > >> experience. I think what I'm trying to do is straightforward, but > because of > >> Facter's key => value pairs model, it's kind of difficult. > > Could you do something like website_count => XXXX ? Then you might not > need to list them out. Either way, you can comma separate strings and > use things like split in Puppet (and maybe stdlib) to do some things. > I used dozens of custom facts in my environment in the past, so I > can't tell you if this is *wrong* way per say. It's a way. Go for it > until you find something better. > > Also note, if you're not really into writing ruby facts, you could use > something in facts.d that is provided via stdlib. That just reads > values from files. You could write your fact in whatever language you > want, run it in cron or something and then have it dump results from > /etc/facter/facts.d or /etc/puppetlabs/facter/facts.d. > > stdlib: http://forge.puppetlabs.com/puppetlabs/stdlib > > >> > >> Each hosts I want the fact for has websites in /var/www/html/ - I want > to be > >> able to do the following: > >> > >> Have a fact called "websites" that will tell me how many folders there > are > >> under /var/www/html > >> > >> Have a list of facts called website_1, website_2, website_3 which will > tell > >> me the names of these sites. Either that or have an array (if that's > even > >> possible) called website_names which will then list all the websites > under > >> that key. > >> > >> If possible, I'd like the fact to be able to figure out how many > websites > >> there are with the original "websites" fact and limit the number of > websites > >> underneath. > >> > >> Any help gratefully appreciated. > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "Puppet Users" group. > >> To view this discussion on the web visit > >> https://groups.google.com/d/msg/puppet-users/-/XBkAAkifbZ4J. > >> To post to this group, send email to puppet-users@googlegroups.com. > >> To unsubscribe from this group, send email to > >> puppet-users+unsubscr...@googlegroups.com. > >> For more options, visit this group at > >> http://groups.google.com/group/puppet-users?hl=en. > > > > > > > > -- > > Walter Heck > > > > -- > > Check out my startup: Puppet training and consulting @ > http://www.olindata.com > > Follow @olindata on Twitter and/or 'Like' our Facebook page at > > http://www.facebook.com/olindata > > > > -- > > 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+unsubscr...@googlegroups.com. > > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > > > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > > -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.