Dear all, I have a custom fact, that reads a file and then generate the values dynamically based on the file content. It''s something like this: inFile = "/home/admin/OSs.txt"> gos = {} > > if File.exist?(inFile) > open(inFile, ''r'').each do |line| > next if line =~ /^\s*(#|$)/ > parts = line.split('','').map(&:strip) > > case parts[1] > when /^Mac/ > (g_C[:mac] ||= []) << parts[0] > when /_Win$/ > (g_C[:win] ||= []) << parts[0] > else > (g_C[:linux] ||= []) << parts[0] > end > end > end > > Facter.add(:am_running_oss) do > has_weight 100 > if gos.count >= 1 > setcode { gos.keys.join('','') } > else > setcode { ''undefined'' } > end > end >The file is on the PuppetMaster. Hence the custom fact ''am_running_oss'' is not available or empty when it runs on the agent. What are the options I have to make the custom facts(s) available on every single puppet agent? Thanks in advance. Cheers!! -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Martin Alfke
2013-Oct-13 10:18 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
Hi, On 13.10.2013, at 10:57, Sans <r.santanu.das@gmail.com> wrote:> [...]> The file is on the PuppetMaster. Hence the custom fact ''am_running_oss'' is not available or empty when it runs on the agent. What are the options I have to make the custom facts(s) available on every single puppet agent? Thanks in advance. Cheers!! >You have to put the fact inside the lib/facter directory of a module and you have to enable pluginsync on all nodes puppet.conf. http://docs.puppetlabs.com/guides/plugins_in_modules.html hth, Martin -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Hi Martin, That doesn''t actually work: I thought exactly the same in the beginning and already have the pluginsync enabled. I think, the reason being, the fact (am_running_oss.rb) file itself reads a text file and the file should be local. When it runs on the agent, the file (inFile = "/home/admin/OSs.txt")is there for the .rb file to read it, hence the fact returns ''undefined''as well. -San On Sunday, October 13, 2013 11:18:46 AM UTC+1, Martin Alfke wrote:> > Hi, > > On 13.10.2013, at 10:57, Sans <r.sant...@gmail.com <javascript:>> wrote: > > > [...] > > > The file is on the PuppetMaster. Hence the custom fact ''am_running_oss'' > is not available or empty when it runs on the agent. What are the options I > have to make the custom facts(s) available on every single puppet agent? > Thanks in advance. Cheers!! > > > > You have to put the fact inside the lib/facter directory of a module and > you have to enable pluginsync on all nodes puppet.conf. > http://docs.puppetlabs.com/guides/plugins_in_modules.html > > hth, > > Martin > > > >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
.....well, unless I''m missing something here. -Santanu On Sunday, October 13, 2013 11:37:19 AM UTC+1, Sans wrote:> > Hi Martin, > > That doesn''t actually work: I thought exactly the same in the beginning > and already have the pluginsync enabled. I think, the reason being, the > fact (am_running_oss.rb) file itself reads a text file and the file should > be local. When it runs on the agent, the file (inFile = > "/home/admin/OSs.txt")is there for the .rb file to read it, hence the > fact returns ''undefined''as well. > > -San > > > > > > On Sunday, October 13, 2013 11:18:46 AM UTC+1, Martin Alfke wrote: >> >> Hi, >> >> On 13.10.2013, at 10:57, Sans <r.sant...@gmail.com> wrote: >> >> > [...] >> >> > The file is on the PuppetMaster. Hence the custom fact ''am_running_oss'' >> is not available or empty when it runs on the agent. What are the options I >> have to make the custom facts(s) available on every single puppet agent? >> Thanks in advance. Cheers!! >> > >> >> You have to put the fact inside the lib/facter directory of a module and >> you have to enable pluginsync on all nodes puppet.conf. >> http://docs.puppetlabs.com/guides/plugins_in_modules.html >> >> hth, >> >> Martin >> >> >> >>-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
To solve my "copying file" issue, I can certainly have a file{} type like this: file { ''running_oss'':> name => ''/home/admin/OSs.txt'', > mode => ''0644'', > content => file(''/home/admin/OSs.txt''); > } >to copy the file from the Master to the agent, but as "Retrieving plugin" stuff happens way before anything else, the file is not copied prior to the custom fact. So, I need to run puppet twice to get the custom fact working on a freshly installed agent. -San On Sunday, October 13, 2013 11:39:22 AM UTC+1, Sans wrote:> > .....well, unless I''m missing something here. > > -Santanu > > > > On Sunday, October 13, 2013 11:37:19 AM UTC+1, Sans wrote: >> >> Hi Martin, >> >> That doesn''t actually work: I thought exactly the same in the beginning >> and already have the pluginsync enabled. I think, the reason being, the >> fact (am_running_oss.rb) file itself reads a text file and the file should >> be local. When it runs on the agent, the file (inFile = >> "/home/admin/OSs.txt")is there for the .rb file to read it, hence the >> fact returns ''undefined''as well. >> >> -San >> >> >> >> >> >> On Sunday, October 13, 2013 11:18:46 AM UTC+1, Martin Alfke wrote: >>> >>> Hi, >>> >>> On 13.10.2013, at 10:57, Sans <r.sant...@gmail.com> wrote: >>> >>> > [...] >>> >>> > The file is on the PuppetMaster. Hence the custom fact >>> ''am_running_oss'' is not available or empty when it runs on the agent. What >>> are the options I have to make the custom facts(s) available on every >>> single puppet agent? Thanks in advance. Cheers!! >>> > >>> >>> You have to put the fact inside the lib/facter directory of a module and >>> you have to enable pluginsync on all nodes puppet.conf. >>> http://docs.puppetlabs.com/guides/plugins_in_modules.html >>> >>> hth, >>> >>> Martin >>> >>> >>> >>>-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Wolf Noble
2013-Oct-13 17:17 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
Hi Santanu, custom facts should always do their work inside a setcode block. http://docs.puppetlabs.com/guides/custom_facts.html That has nothing to do with the issue at hand, however. If you need the file to exist before puppet''s first run, have your provisioning system lay it down. Otherwise, you''ll have the situation you''re describing where your first puppet run''s job is to set the stage for the rest of your runs. hth W On Sun, Oct 13, 2013 at 6:30 AM, Sans <r.santanu.das@gmail.com> wrote:> To solve my "copying file" issue, I can certainly have a file{} type like > this: > > file { ''running_oss'': >> name => ''/home/admin/OSs.txt'', >> mode => ''0644'', >> content => file(''/home/admin/OSs.txt''); >> } >> > > to copy the file from the Master to the agent, but as "Retrieving plugin" stuff > happens way before anything else, the file is not copied prior to the > custom fact. So, I need to run puppet twice to get the custom fact working > on a freshly installed agent. > > -San > > > > > On Sunday, October 13, 2013 11:39:22 AM UTC+1, Sans wrote: >> >> .....well, unless I''m missing something here. >> >> -Santanu >> >> >> >> On Sunday, October 13, 2013 11:37:19 AM UTC+1, Sans wrote: >>> >>> Hi Martin, >>> >>> That doesn''t actually work: I thought exactly the same in the beginning >>> and already have the pluginsync enabled. I think, the reason being, the >>> fact (am_running_oss.rb) file itself reads a text file and the file should >>> be local. When it runs on the agent, the file (inFile >>> "/home/admin/OSs.txt")is there for the .rb file to read it, hence the >>> fact returns ''undefined''as well. >>> >>> -San >>> >>> >>> >>> >>> >>> On Sunday, October 13, 2013 11:18:46 AM UTC+1, Martin Alfke wrote: >>>> >>>> Hi, >>>> >>>> On 13.10.2013, at 10:57, Sans <r.sant...@gmail.com> wrote: >>>> >>>> > [...] >>>> >>>> > The file is on the PuppetMaster. Hence the custom fact >>>> ''am_running_oss'' is not available or empty when it runs on the agent. What >>>> are the options I have to make the custom facts(s) available on every >>>> single puppet agent? Thanks in advance. Cheers!! >>>> > >>>> >>>> You have to put the fact inside the lib/facter directory of a module >>>> and you have to enable pluginsync on all nodes puppet.conf. >>>> http://docs.puppetlabs.com/**guides/plugins_in_modules.html<http://docs.puppetlabs.com/guides/plugins_in_modules.html> >>>> >>>> hth, >>>> >>>> Martin >>>> >>>> >>>> >>>> -- > 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 puppet-users+unsubscribe@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > Visit this group at http://groups.google.com/group/puppet-users. > 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Hi Wolf, yes, the custom fact itself is working just fine, so that''s not a prob at all. It''s something like this: inFile = "/home/admin/OSs.txt"> gos = {} > > if File.exist?(inFile) > open(inFile, ''r'').each do |line| > next if line =~ /^\s*(#|$)/ > parts = line.split('','').map(&:strip) > > case parts[1] > when /^Mac/ > (gos[:mac] ||= []) << parts[0] > when /_Win$/ > (gos[:win] ||= []) << parts[0] > else > (gos[:linux] ||= []) << parts[0] > end > end > end > > Facter.add(:am_running_oss) do > has_weight 100 > if gos.count >= 1 > setcode { gos.keys.join('','') } > else > setcode { ''undefined'' } > end > end >As you can see, the problem is the very first line. BTW, w.r.t. "provisioning system", it''s a bit of mess at the moment and I don''t wanna touch it before the demo, that we have in two weeks time. It''s a ENC based system, which we replaced by a master-less Puppet (for AWS) implementation and then back to old ENC system again as we started having problem with our cloud provisioning. So, right now, it does ship the file on to the PM and whatever the extra stuff I''m putting in doing from modules; one of the modules needs that file available on every host for that custom-fact to work. Thanks anyway. Cheers!! On Sunday, October 13, 2013 6:17:06 PM UTC+1, Wolf Noble wrote:> > Hi Santanu, > > custom facts should always do their work inside a setcode block. > http://docs.puppetlabs.com/guides/custom_facts.html > > That has nothing to do with the issue at hand, however. > > If you need the file to exist before puppet''s first run, have your > provisioning system lay it down. Otherwise, you''ll have the situation > you''re describing where your first puppet run''s job is to set the stage for > the rest of your runs. > > hth > > W >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Cristian Falcas
2013-Oct-13 20:04 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
Why not make your fact a function? This way it will only run on the master and you will use a return value in your manifests instead of facts. On Sun, Oct 13, 2013 at 10:42 PM, Sans <r.santanu.das@gmail.com> wrote:> Hi Wolf, > > yes, the custom fact itself is working just fine, so that''s not a prob at > all. It''s something like this: > >> inFile = "/home/admin/OSs.txt" >> gos = {} >> >> if File.exist?(inFile) >> open(inFile, ''r'').each do |line| >> next if line =~ /^\s*(#|$)/ >> parts = line.split('','').map(&:strip) >> >> case parts[1] >> when /^Mac/ >> (gos[:mac] ||= []) << parts[0] >> when /_Win$/ >> (gos[:win] ||= []) << parts[0] >> else >> (gos[:linux] ||= []) << parts[0] >> >> end >> end >> end >> >> Facter.add(:am_running_oss) do >> has_weight 100 >> if gos.count >= 1 >> setcode { gos.keys.join('','') } >> else >> setcode { ''undefined'' } >> end >> end > > > > As you can see, the problem is the very first line. > BTW, w.r.t. "provisioning system", it''s a bit of mess at the moment and I > don''t wanna touch it before the demo, that we have in two weeks time. It''s a > ENC based system, which we replaced by a master-less Puppet (for AWS) > implementation and then back to old ENC system again as we started having > problem with our cloud provisioning. So, right now, it does ship the file on > to the PM and whatever the extra stuff I''m putting in doing from modules; > one of the modules needs that file available on every host for that > custom-fact to work. Thanks anyway. Cheers!! > > > > > > On Sunday, October 13, 2013 6:17:06 PM UTC+1, Wolf Noble wrote: >> >> Hi Santanu, >> >> custom facts should always do their work inside a setcode block. >> http://docs.puppetlabs.com/guides/custom_facts.html >> >> That has nothing to do with the issue at hand, however. >> >> If you need the file to exist before puppet''s first run, have your >> provisioning system lay it down. Otherwise, you''ll have the situation you''re >> describing where your first puppet run''s job is to set the stage for the >> rest of your runs. >> >> hth >> >> W > > -- > 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 puppet-users+unsubscribe@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > Visit this group at http://groups.google.com/group/puppet-users. > 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Hi Cristian, That sounds a workable solution. Do you have any example handy; I''ve never used that before. -San On Sunday, October 13, 2013 9:04:09 PM UTC+1, Cristian Falcas wrote:> > Why not make your fact a function? > > This way it will only run on the master and you will use a return > value in your manifests instead of facts. > > >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Oct-14 15:03 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
On Sunday, October 13, 2013 4:53:10 PM UTC-5, Sans wrote:> > Hi Cristian, > > That sounds a workable solution. >Unlikely. Custom functions run on the master during catalog compilation. If you need data from a local file on the node to compute the correct value for your erstwhile $::am_running_oss fact then changing the fact to a function will not improve that data''s availablility. On the other hand, if the idea is that the content of /home/admin/OSs.txt is managed exclusively by Puppet in the first place, then what''s the point? The master must already have enough information to determine what that file is supposed to contain, and thus what the fact value is supposed to be. Just set a variable in an appropriate class with the appropriate computed value, and skip the fact altogether. If you only needed the file to support the fact, then dump the file, too. John -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Cristian Falcas
2013-Oct-14 20:37 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
i understood that the file is only on the master? If so, I will try to write something tomorrow to implement this, If the value never changes, it will be better to put it in an external variable. On Mon, Oct 14, 2013 at 6:03 PM, jcbollinger <John.Bollinger@stjude.org> wrote:> > > On Sunday, October 13, 2013 4:53:10 PM UTC-5, Sans wrote: >> >> Hi Cristian, >> >> That sounds a workable solution. > > > > Unlikely. Custom functions run on the master during catalog compilation. > If you need data from a local file on the node to compute the correct value > for your erstwhile $::am_running_oss fact then changing the fact to a > function will not improve that data''s availablility. > > On the other hand, if the idea is that the content of /home/admin/OSs.txt is > managed exclusively by Puppet in the first place, then what''s the point? > The master must already have enough information to determine what that file > is supposed to contain, and thus what the fact value is supposed to be. > Just set a variable in an appropriate class with the appropriate computed > value, and skip the fact altogether. If you only needed the file to support > the fact, then dump the file, too. > > > John > > -- > 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 puppet-users+unsubscribe@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > Visit this group at http://groups.google.com/group/puppet-users. > 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Yes, the file is only on the master (and not exactly maintained by the Puppet but the provisioning framework) and it looks something like this: Slackware, Linux, i-num=1> Jaguar, MacX, i-num=6 > Chicago, this_Win, i-num=2 > Daytona, an_other_Win, i-num=7 > RedHat, Linux, i-num=5 > Lion, MacY, i-num=4 > Caldera, Linux, i-num=9 > Longhorn, that_Win, i-num=8 > Tiger, MacZ, i-num=3 > Indiana, Solaris, i-num=10 > Kodiak, MacX, i-num=11 >What I was trying to do is to get a fact (or function) that returns a string like: "win,mac,linux", as I showed in my previous post. Really appreciate if you can make an example function out of that. cheers!! On Monday, October 14, 2013 9:37:51 PM UTC+1, Cristian Falcas wrote:> > i understood that the file is only on the master? If so, I will try to > write something tomorrow to implement this, > > If the value never changes, it will be better to put it in an external > variable. > >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Cristian Falcas
2013-Oct-15 13:26 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
Put in $your_module_name/lib/puppet/parser/functions/am_running_oss.rb module Puppet::Parser::Functions newfunction(:am_running_oss, :type => :rvalue ) do |args| #inFile = "/tmp/OSs.txt" inFile = args[0] gos = {} if File.exist?(inFile) open(inFile, ''r'').each do |line| next if line =~ /^\s*(#|$)/ parts = line.split('','').map(&:strip) case parts[1] when /^Mac/ (gos[:mac] ||= []) << parts[0] #gos[''1''] when /_Win$/ (gos[:win] ||= []) << parts[0] else (gos[:linux] ||= []) << parts[0] end end end if gos.count >= 1 return gos.keys.join('','') else return ''undefined'' end end end And from your module: $q=am_running_oss("/tmp/OSs.txt") notify {"XXXXXXXX ${q}":} Also, you could skip the parameter and just hard coded in the file. On Tue, Oct 15, 2013 at 9:03 AM, Sans <r.santanu.das@gmail.com> wrote:> > Yes, the file is only on the master (and not exactly maintained by the > Puppet but the provisioning framework) and it looks something like this: > > >> Slackware, Linux, i-num=1 >> Jaguar, MacX, i-num=6 >> Chicago, this_Win, i-num=2 >> Daytona, an_other_Win, i-num=7 >> RedHat, Linux, i-num=5 >> Lion, MacY, i-num=4 >> Caldera, Linux, i-num=9 >> Longhorn, that_Win, i-num=8 >> Tiger, MacZ, i-num=3 >> Indiana, Solaris, i-num=10 >> Kodiak, MacX, i-num=11 > > > > What I was trying to do is to get a fact (or function) that returns a string > like: "win,mac,linux", as I showed in my previous post. Really appreciate if > you can make an example function out of that. cheers!! > > > > > On Monday, October 14, 2013 9:37:51 PM UTC+1, Cristian Falcas wrote: >> >> i understood that the file is only on the master? If so, I will try to >> write something tomorrow to implement this, >> >> If the value never changes, it will be better to put it in an external >> variable. >> > -- > 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 puppet-users+unsubscribe@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > Visit this group at http://groups.google.com/group/puppet-users. > 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Cristian Falcas
2013-Oct-15 13:27 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
I''ve changed your g_C[:mac] to gos[:mac], because I don''t know what it should do and puppet complained about it. On Tue, Oct 15, 2013 at 4:26 PM, Cristian Falcas <cristi.falcas@gmail.com> wrote:> Put in $your_module_name/lib/puppet/parser/functions/am_running_oss.rb > > > module Puppet::Parser::Functions > newfunction(:am_running_oss, :type => :rvalue ) do |args| > #inFile = "/tmp/OSs.txt" > inFile = args[0] > gos = {} > > if File.exist?(inFile) > open(inFile, ''r'').each do |line| > next if line =~ /^\s*(#|$)/ > parts = line.split('','').map(&:strip) > > case parts[1] > when /^Mac/ > (gos[:mac] ||= []) << parts[0] > #gos[''1''] > when /_Win$/ > (gos[:win] ||= []) << parts[0] > else > (gos[:linux] ||= []) << parts[0] > end > end > end > if gos.count >= 1 > return gos.keys.join('','') > else > return ''undefined'' > end > end > end > > And from your module: > > $q=am_running_oss("/tmp/OSs.txt") > notify {"XXXXXXXX ${q}":} > > > Also, you could skip the parameter and just hard coded in the file. > > > > On Tue, Oct 15, 2013 at 9:03 AM, Sans <r.santanu.das@gmail.com> wrote: >> >> Yes, the file is only on the master (and not exactly maintained by the >> Puppet but the provisioning framework) and it looks something like this: >> >> >>> Slackware, Linux, i-num=1 >>> Jaguar, MacX, i-num=6 >>> Chicago, this_Win, i-num=2 >>> Daytona, an_other_Win, i-num=7 >>> RedHat, Linux, i-num=5 >>> Lion, MacY, i-num=4 >>> Caldera, Linux, i-num=9 >>> Longhorn, that_Win, i-num=8 >>> Tiger, MacZ, i-num=3 >>> Indiana, Solaris, i-num=10 >>> Kodiak, MacX, i-num=11 >> >> >> >> What I was trying to do is to get a fact (or function) that returns a string >> like: "win,mac,linux", as I showed in my previous post. Really appreciate if >> you can make an example function out of that. cheers!! >> >> >> >> >> On Monday, October 14, 2013 9:37:51 PM UTC+1, Cristian Falcas wrote: >>> >>> i understood that the file is only on the master? If so, I will try to >>> write something tomorrow to implement this, >>> >>> If the value never changes, it will be better to put it in an external >>> variable. >>> >> -- >> 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 puppet-users+unsubscribe@googlegroups.com. >> To post to this group, send email to puppet-users@googlegroups.com. >> Visit this group at http://groups.google.com/group/puppet-users. >> 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Hi Cristian, Thanks for the code. gos[:mac] is the right thing to do (as we defined: gos = {}); I think I g_C was a typo in my example script somewhere down the line). One related question: as I read that the name of the file must be the same as the name of the function, then I suppose I cannot do something similar to this in function: gos.each_key do |cls|> Facter.add(''am_oss_'' + cls.to_s) do > setcode { gos[cls][0] } > end > end >as one can easily do with custom-facts? Any workaround available to this issue? Cheers!! On Tuesday, October 15, 2013 2:27:00 PM UTC+1, Cristian Falcas wrote:> > I''ve changed your g_C[:mac] to gos[:mac], because I don''t know what it > should do and puppet complained about it. > > >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Cristian Falcas
2013-Oct-16 10:45 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
You could return a hash, or an array if you need multiple from the function. On Wed, Oct 16, 2013 at 12:11 PM, Sans <r.santanu.das@gmail.com> wrote:> Hi Cristian, > > Thanks for the code. gos[:mac] is the right thing to do (as we defined: gos > = {}); I think I g_C was a typo in my example script somewhere down the > line). > > One related question: as I read that the name of the file must be the same > as the name of the function, then I suppose I cannot do something similar to > this in function: > > >> gos.each_key do |cls| >> Facter.add(''am_oss_'' + cls.to_s) do >> setcode { gos[cls][0] } >> end >> end > > > > as one can easily do with custom-facts? Any workaround available to this > issue? Cheers!! > > > > On Tuesday, October 15, 2013 2:27:00 PM UTC+1, Cristian Falcas wrote: >> >> I''ve changed your g_C[:mac] to gos[:mac], because I don''t know what it >> should do and puppet complained about it. >> >> > -- > 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 puppet-users+unsubscribe@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > Visit this group at http://groups.google.com/group/puppet-users. > 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
I just modified your code a little bit and created two function out of that: *# am_running_oss_hash.rb*> module Puppet::Parser::Functions > newfunction(:am_running_oss_hash, :type => :rvalue ) do |args| > inFile = args[0] > gos = {} > > if File.exist?(inFile) > open(inFile, ''r'').each do |line| > next if line =~ /^\s*(#|$)/ > parts = line.split('','').map(&:strip) > > case parts[1] > when /^Mac/ > (gos[:mac] ||= []) << parts[0] > when /_Win$/ > (gos[:win] ||= []) << parts[0] > else > (gos[:linux] ||= []) << parts[0] > end > end > end > > return gos > end > end >*# am_running_oss.rb*> module Puppet::Parser::Functions > newfunction(:am_running_oss, :type => :rvalue ) do |args| > #Puppet::Parser::Functions.function(''am_running_oss_hash'') > Puppet::Parser::Functions.autoloader.loadall > > oss = function_am_running_oss_hash([''/tmp/OSs.txt'']) > if oss.count >= 1 > return oss.keys.join('','') > else > return ''undefined'' > end > end > end >and then in the module: $h = am_running_oss()> notify {"=*=*= RunnigOSS <|:|> ${h} =*=*=*=*=*=*=*=":} >but I''m getting this error: Error: Could not retrieve catalog from remote server: Error 400 on SERVER:> custom functions must be called with a single array that contains the > arguments. For example, function_example([1]) instead of function_example(1) >What am I doing wrong? Cheers!! On Wednesday, October 16, 2013 11:45:42 AM UTC+1, Cristian Falcas wrote:> > You could return a hash, or an array if you need multiple from the > function. > > >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Cristian Falcas
2013-Oct-16 21:35 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
Check this: http://docs.puppetlabs.com/guides/custom_functions.html#calling-functions-from-functions On Thu, Oct 17, 2013 at 12:08 AM, Sans <r.santanu.das@gmail.com> wrote:> > I just modified your code a little bit and created two function out of that: > > > # am_running_oss_hash.rb >> >> module Puppet::Parser::Functions >> newfunction(:am_running_oss_hash, :type => :rvalue ) do |args| >> >> inFile = args[0] >> gos = {} >> >> if File.exist?(inFile) >> open(inFile, ''r'').each do |line| >> next if line =~ /^\s*(#|$)/ >> parts = line.split('','').map(&:strip) >> >> case parts[1] >> when /^Mac/ >> (gos[:mac] ||= []) << parts[0] >> when /_Win$/ >> (gos[:win] ||= []) << parts[0] >> else >> (gos[:linux] ||= []) << parts[0] >> end >> end >> end >> >> return gos >> end >> end > > > > # am_running_oss.rb >> >> module Puppet::Parser::Functions >> newfunction(:am_running_oss, :type => :rvalue ) do |args| >> #Puppet::Parser::Functions.function(''am_running_oss_hash'') >> Puppet::Parser::Functions.autoloader.loadall >> >> oss = function_am_running_oss_hash([''/tmp/OSs.txt'']) >> if oss.count >= 1 >> return oss.keys.join('','') >> >> else >> return ''undefined'' >> end >> end >> end > > > > and then in the module: > >> $h = am_running_oss() >> notify {"=*=*= RunnigOSS <|:|> ${h} =*=*=*=*=*=*=*=":} > > > > but I''m getting this error: > >> Error: Could not retrieve catalog from remote server: Error 400 on SERVER: >> custom functions must be called with a single array that contains the >> arguments. For example, function_example([1]) instead of function_example(1) > > > > What am I doing wrong? Cheers!! > > > > On Wednesday, October 16, 2013 11:45:42 AM UTC+1, Cristian Falcas wrote: >> >> You could return a hash, or an array if you need multiple from the >> function. >> >> > -- > 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 puppet-users+unsubscribe@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > Visit this group at http://groups.google.com/group/puppet-users. > 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Cristian Falcas
2013-Oct-16 21:37 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
sorry, i didn''t see that you already did that. I will try to respond again more meaningful in the morning On Thu, Oct 17, 2013 at 12:35 AM, Cristian Falcas <cristi.falcas@gmail.com> wrote:> Check this: > > http://docs.puppetlabs.com/guides/custom_functions.html#calling-functions-from-functions > > > > On Thu, Oct 17, 2013 at 12:08 AM, Sans <r.santanu.das@gmail.com> wrote: >> >> I just modified your code a little bit and created two function out of that: >> >> >> # am_running_oss_hash.rb >>> >>> module Puppet::Parser::Functions >>> newfunction(:am_running_oss_hash, :type => :rvalue ) do |args| >>> >>> inFile = args[0] >>> gos = {} >>> >>> if File.exist?(inFile) >>> open(inFile, ''r'').each do |line| >>> next if line =~ /^\s*(#|$)/ >>> parts = line.split('','').map(&:strip) >>> >>> case parts[1] >>> when /^Mac/ >>> (gos[:mac] ||= []) << parts[0] >>> when /_Win$/ >>> (gos[:win] ||= []) << parts[0] >>> else >>> (gos[:linux] ||= []) << parts[0] >>> end >>> end >>> end >>> >>> return gos >>> end >>> end >> >> >> >> # am_running_oss.rb >>> >>> module Puppet::Parser::Functions >>> newfunction(:am_running_oss, :type => :rvalue ) do |args| >>> #Puppet::Parser::Functions.function(''am_running_oss_hash'') >>> Puppet::Parser::Functions.autoloader.loadall >>> >>> oss = function_am_running_oss_hash([''/tmp/OSs.txt'']) >>> if oss.count >= 1 >>> return oss.keys.join('','') >>> >>> else >>> return ''undefined'' >>> end >>> end >>> end >> >> >> >> and then in the module: >> >>> $h = am_running_oss() >>> notify {"=*=*= RunnigOSS <|:|> ${h} =*=*=*=*=*=*=*=":} >> >> >> >> but I''m getting this error: >> >>> Error: Could not retrieve catalog from remote server: Error 400 on SERVER: >>> custom functions must be called with a single array that contains the >>> arguments. For example, function_example([1]) instead of function_example(1) >> >> >> >> What am I doing wrong? Cheers!! >> >> >> >> On Wednesday, October 16, 2013 11:45:42 AM UTC+1, Cristian Falcas wrote: >>> >>> You could return a hash, or an array if you need multiple from the >>> function. >>> >>> >> -- >> 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 puppet-users+unsubscribe@googlegroups.com. >> To post to this group, send email to puppet-users@googlegroups.com. >> Visit this group at http://groups.google.com/group/puppet-users. >> 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Not sure if it''s important: the line number in the error message points to the line in the .pp file where "$h = am_running_oss()" is defines. If I change that line with "am_running_oss_hash(''/tmp/OSs.txt'')" it works just fine. Cheers!! On Wednesday, October 16, 2013 10:37:19 PM UTC+1, Cristian Falcas wrote:> > sorry, i didn''t see that you already did that. I will try to respond > again more meaningful in the morning > > >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
It''s strange: whatever I do I can''t go past these error. Either it cannot recognize the function or fails with single array error. Still don''t understand what I''m missing. Cheers!! On Thursday, October 17, 2013 1:34:26 AM UTC+1, Sans wrote:> > Not sure if it''s important: the line number in the error message points to > the line in the .pp file where "$h = am_running_oss()" is defines. If I > change that line with "am_running_oss_hash(''/tmp/OSs.txt'')" it works just > fine. Cheers!! >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Oct-18 13:24 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
On Wednesday, October 16, 2013 7:34:26 PM UTC-5, Sans wrote:> > Not sure if it''s important: the line number in the error message points to > the line in the .pp file where "$h = am_running_oss()" is defines. If I > change that line with "am_running_oss_hash(''/tmp/OSs.txt'')" it works just > fine. Cheers!! > >Be sure to restart your master after modifying any custom functions. If you have not done so, then the master might not see the changes. The error you posted should arise only in the context of a native plugin trying to call a Puppet function, and the only place where your code does that is this line: oss = function_am_running_oss_hash([''/tmp/OSs.txt'']) That is correct as it stands, but if a previous version of the code omitted the square brackets then it would cause such an error. John> > > > On Wednesday, October 16, 2013 10:37:19 PM UTC+1, Cristian Falcas wrote: >> >> sorry, i didn''t see that you already did that. I will try to respond >> again more meaningful in the morning >> >> >>-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Oct-18 13:32 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
On Thursday, October 17, 2013 8:21:28 AM UTC-5, Sans wrote:> > It''s strange: whatever I do I can''t go past these error. Either it cannot > recognize the function or fails with single array error. Still don''t > understand what I''m missing. Cheers!! > > > On Thursday, October 17, 2013 1:34:26 AM UTC+1, Sans wrote: >> >> Not sure if it''s important: the line number in the error message points >> to the line in the .pp file where "$h = am_running_oss()" is defines. >> If I change that line with "am_running_oss_hash(''/tmp/OSs.txt'')" it >> works just fine. Cheers!! >> >What if you use $h = am_running_oss(1) (or replace the 1 with any other value)? Puppet shouldn''t break when the argument list is empty, but perhaps you''ve stumbled on a bug. John -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Dwayne Lee
2013-Oct-18 15:17 UTC
Re: [Puppet Users] exporting custom facts to puppet agents
I had issues with custom facts returning errors and or not finding the custom facts until I created an additional module called "facterpath". Here is the init.pp: # /etc/puppet/modules/facterpath/manifests/init.pp class facterpath { file { "/etc/profile.d/facter.sh": owner => ''root'', group => ''root'', mode => ''0644'', source => "puppet:///files/etc/profile.d/facter.sh", } } It simply pushes a facter.sh file to /etc/profile.d on all of my agents. Here''s the file that gets pushed: # cat /etc/profile.d/facter.sh export FACTERLIB=$FACTERLIB:/var/lib/puppet/lib/facter So now when I log in the facter library becomes part of my ENV and no more issues in using the custom facts on my agents. ***************************** On Sunday, October 13, 2013 6:18:46 AM UTC-4, Martin Alfke wrote:> > Hi, > > On 13.10.2013, at 10:57, Sans <r.sant...@gmail.com <javascript:>> wrote: > > > [...] > > > The file is on the PuppetMaster. Hence the custom fact ''am_running_oss'' > is not available or empty when it runs on the agent. What are the options I > have to make the custom facts(s) available on every single puppet agent? > Thanks in advance. Cheers!! > > > > You have to put the fact inside the lib/facter directory of a module and > you have to enable pluginsync on all nodes puppet.conf. > http://docs.puppetlabs.com/guides/plugins_in_modules.html > > hth, > > Martin > > > >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Thanks John! That''s it! feel myself like the biggest stupid in the world! Thanks every one for the help. It''s working just fine now. Cheers!! On Friday, October 18, 2013 2:24:29 PM UTC+1, jcbollinger wrote:> > > > *Be sure to restart your master after modifying any custom functions. If > you have not done so, then the master might not see the changes.** > * > [ .....] > John > >-- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.