Hi, I''ve seen some blog posts about adding server roles to Puppet. Some of them with this fact snippet: if File.exists?("/etc/roles.txt") File.readlines("/etc/roles.txt").each do |line| if line =~ /^(.+)=(.+)$/ fact = $1 value = $2 Facter.add(fact) do # confine :kernel => "Linux" setcode {value} end end end end Since I have both linux and windows boxes backed with Puppet, it is correct to add the "confine :kernel => "Linux"" next to "Facter.add(fact) and replicate the whole block changing this "confine :kernel to "Windows" and the path (to match window paths c:\foo)? Is this the right approach? thanks in advance. Cheers, -- Frank -- 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.
On Friday, September 28, 2012 6:05:54 AM UTC-5, ureal frank wrote:> > Hi, > > I''ve seen some blog posts about adding server roles to Puppet. > > Some of them with this fact snippet: > > if File.exists?("/etc/roles.txt") > File.readlines("/etc/roles.txt").each do |line| > if line =~ /^(.+)=(.+)$/ > fact = $1 > value = $2 > > Facter.add(fact) do > # confine :kernel => "Linux" > setcode {value} > end > end > end > end > > > Since I have both linux and windows boxes backed with Puppet, it is > correct to add the "confine :kernel => "Linux"" next to "Facter.add(fact) > and replicate the whole block changing this "confine :kernel to "Windows" > and the path (to match window paths c:\foo)? > > Is this the right approach? >No. The code you presented tests the Unix-style path well before it gets to the point where your confine enters the picture. If the file was found at all then you do not need to ''confine'' to Linux (unless you need to distinguish that case from other Unixes, such as OS X or Solaris). You could duplicate the code and change the path (still not needing a ''confine''), but if I were writing this I would probably test the "kernel" or "os" fact at the start to determine which path to look for in the first place, then use just one fact declaration (still with no need for a ''confine''). John -- 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/-/q1jyUOogM0cJ. 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.
-- Frank On Friday, September 28, 2012 at 2:35 PM, jcbollinger wrote:> > > On Friday, September 28, 2012 6:05:54 AM UTC-5, ureal frank wrote: > > Hi, > > > > I''ve seen some blog posts about adding server roles to Puppet. > > > > Some of them with this fact snippet: > > > > if File.exists?("/etc/roles.txt") > > File.readlines("/etc/roles.txt").each do |line| > > if line =~ /^(.+)=(.+)$/ > > fact = $1 > > value = $2 > > > > Facter.add(fact) do > > # confine :kernel => "Linux" > > setcode {value} > > end > > end > > end > > end > > > > > > > > Since I have both linux and windows boxes backed with Puppet, it is correct to add the "confine :kernel => "Linux"" next to "Facter.add(fact) and replicate the whole block changing this "confine :kernel to "Windows" and the path (to match window paths c:\foo)? > > > > Is this the right approach? > > > No. The code you presented tests the Unix-style path well before it gets to the point where your confine enters the picture. If the file was found at all then you do not need to ''confine'' to Linux (unless you need to distinguish that case from other Unixes, such as OS X or Solaris). > > You could duplicate the code and change the path (still not needing a ''confine''), but if I were writing this I would probably test the "kernel" or "os" fact at the start to determine which path to look for in the first place, then use just one fact declaration (still with no need for a ''confine'').Ok, it makes sense. Then for me to use $$::kernel variable on this fact definition, I must require ''facter'' first or I just use it in a conditional clause like this? if $::kernel = "linux" then # linux fact code else # windows fact code end Frank> > > John > > -- > 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/-/q1jyUOogM0cJ. > To post to this group, send email to puppet-users@googlegroups.com (mailto:puppet-users@googlegroups.com). > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com (mailto:puppet-users+unsubscribe@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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
I''m going this way: roles_file = "" if Facter.kernel = ''linux'' roles_file = "/etc/roles_facts.txt" elsif Facter.kernel = ''windows'' roles_file = "C:\\roles_facts.txt" end if File.exists?(roles_files) File.readlines(roles_file).each do |line| if line =~ /^(.+)=(.+)$/ fact = $1 value = $2 Facter.add(fact) do setcode {value} end end end end :) -- Frank On Friday, September 28, 2012 at 2:44 PM, Frank wrote:> > > -- > Frank > > > On Friday, September 28, 2012 at 2:35 PM, jcbollinger wrote: > > > > > > > On Friday, September 28, 2012 6:05:54 AM UTC-5, ureal frank wrote: > > > Hi, > > > > > > I''ve seen some blog posts about adding server roles to Puppet. > > > > > > Some of them with this fact snippet: > > > > > > if File.exists?("/etc/roles.txt") > > > File.readlines("/etc/roles.txt").each do |line| > > > if line =~ /^(.+)=(.+)$/ > > > fact = $1 > > > value = $2 > > > > > > Facter.add(fact) do > > > # confine :kernel => "Linux" > > > setcode {value} > > > end > > > end > > > end > > > end > > > > > > > > > > > > Since I have both linux and windows boxes backed with Puppet, it is correct to add the "confine :kernel => "Linux"" next to "Facter.add(fact) and replicate the whole block changing this "confine :kernel to "Windows" and the path (to match window paths c:\foo)? > > > > > > Is this the right approach? > > > > > > No. The code you presented tests the Unix-style path well before it gets to the point where your confine enters the picture. If the file was found at all then you do not need to ''confine'' to Linux (unless you need to distinguish that case from other Unixes, such as OS X or Solaris). > > > > You could duplicate the code and change the path (still not needing a ''confine''), but if I were writing this I would probably test the "kernel" or "os" fact at the start to determine which path to look for in the first place, then use just one fact declaration (still with no need for a ''confine''). > > Ok, it makes sense. Then for me to use $$::kernel variable on this fact definition, I must require ''facter'' first or I just use it in a conditional clause like this? > > if $::kernel = "linux" then > # linux fact code > else > # windows fact code > end > > > Frank > > > > > > > John > > > > -- > > 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/-/q1jyUOogM0cJ. > > To post to this group, send email to puppet-users@googlegroups.com (mailto:puppet-users@googlegroups.com). > > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com (mailto:puppet-users+unsubscribe@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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.