Hi all, I have a custom facts script that is distributed to all of my puppet clients. This first thing this script does is read a file on the client to determine the ''type'' of server that it is. Later in the script, I would like to change the value based on some additional information. I don''t seem to be able to modify the value of a fact once it has been set. For example Facter.add("server_type") do setcode do "apache_web_server" end end # Later I may want to change the value. if Facter.value("http_server") = "false" # Change value of "server_type" here. I have tried many different approaches but none work. end Any advice would be greatly 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/-/AXcBrQsr4YsJ. 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.
Of course should be == and not if Facter.value("http_server") == "false" # Change value of "server_type" here. I have tried many different approaches but none work. end On Tuesday, July 31, 2012 2:38:15 PM UTC-6, rjl wrote:> > Hi all, > I have a custom facts script that is distributed to all of my puppet > clients. This first thing this script does is read a file on the client to > determine the ''type'' of server that it is. Later in the script, I would > like to change the value based on some additional information. I don''t seem > to be able to modify the value of a fact once it has been set. For example > > Facter.add("server_type") do > setcode do > "apache_web_server" > end > end > > # Later I may want to change the value. > > if Facter.value("http_server") = "false" > # Change value of "server_type" here. I have tried many different > approaches but none work. > end > > Any advice would be greatly 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/-/ZAR3EpUQvYUJ. 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.
It may be best to hold your value in a temporary variable and just have the setcode run at the end. I can''t remember where I read it, but I don''t think ruby custom facts can override other ruby custom facts once they are set (thought I believe the FACTER_ environment variables can override ruby custom facts). On Tuesday, July 31, 2012 3:38:15 PM UTC-5, rjl wrote:> > Hi all, > I have a custom facts script that is distributed to all of my puppet > clients. This first thing this script does is read a file on the client to > determine the ''type'' of server that it is. Later in the script, I would > like to change the value based on some additional information. I don''t seem > to be able to modify the value of a fact once it has been set. For example > > Facter.add("server_type") do > setcode do > "apache_web_server" > end > end > > # Later I may want to change the value. > > if Facter.value("http_server") = "false" > # Change value of "server_type" here. I have tried many different > approaches but none work. > end > > Any advice would be greatly 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/-/QQFBsSymMs8J. 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.
Thanks ZJE. That is what I ended up doing. On Tuesday, July 31, 2012 2:50:44 PM UTC-6, ZJE wrote:> > It may be best to hold your value in a temporary variable and just have > the setcode run at the end. I can''t remember where I read it, but I don''t > think ruby custom facts can override other ruby custom facts once they are > set (thought I believe the FACTER_ environment variables can override ruby > custom facts). > > On Tuesday, July 31, 2012 3:38:15 PM UTC-5, rjl wrote: >> >> Hi all, >> I have a custom facts script that is distributed to all of my puppet >> clients. This first thing this script does is read a file on the client to >> determine the ''type'' of server that it is. Later in the script, I would >> like to change the value based on some additional information. I don''t seem >> to be able to modify the value of a fact once it has been set. For example >> >> Facter.add("server_type") do >> setcode do >> "apache_web_server" >> end >> end >> >> # Later I may want to change the value. >> >> if Facter.value("http_server") = "false" >> # Change value of "server_type" here. I have tried many different >> approaches but none work. >> end >> >> Any advice would be greatly 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/-/1YHE2l76EAgJ. 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.
You can have multiple resolutions for a single fact, and use fact precedence to determine which ones should be used first. http://docs.puppetlabs.com/guides/custom_facts.html#fact-precedence has the details on this. On Tue, Jul 31, 2012 at 3:24 PM, rjl <rjlindal@gmail.com> wrote:> Thanks ZJE. That is what I ended up doing. > > > On Tuesday, July 31, 2012 2:50:44 PM UTC-6, ZJE wrote: >> >> It may be best to hold your value in a temporary variable and just have >> the setcode run at the end. I can''t remember where I read it, but I don''t >> think ruby custom facts can override other ruby custom facts once they are >> set (thought I believe the FACTER_ environment variables can override ruby >> custom facts). >> >> On Tuesday, July 31, 2012 3:38:15 PM UTC-5, rjl wrote: >>> >>> Hi all, >>> I have a custom facts script that is distributed to all of my puppet >>> clients. This first thing this script does is read a file on the client to >>> determine the ''type'' of server that it is. Later in the script, I would >>> like to change the value based on some additional information. I don''t seem >>> to be able to modify the value of a fact once it has been set. For example >>> >>> Facter.add("server_type") do >>> setcode do >>> "apache_web_server" >>> end >>> end >>> >>> # Later I may want to change the value. >>> >>> if Facter.value("http_server") = "false" >>> # Change value of "server_type" here. I have tried many different >>> approaches but none work. >>> end >>> >>> Any advice would be greatly 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/-/1YHE2l76EAgJ. > > 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. >-- Adrien Thebo | Puppet Labs Operations -- 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 doing something similar in one environment… I''ve come to realize this method contains less awesome than I''d anticipated. What I''d suggest doing, is changing the file deployed to the client into a template that''s deployed via puppet.. have that template set the content correctly for the machine in question when it''s deployed. The HOW you go about doing that varies greatly depending on your environment… This way you''re not trying to override facts, which is generally an adventure in undergoodness. my $.02 On Jul 31, 2012, at 3:38 PM, rjl <rjlindal@gmail.com> wrote:> Hi all, > I have a custom facts script that is distributed to all of my puppet clients. This first thing this script does is read a file on the client to determine the ''type'' of server that it is. Later in the script, I would like to change the value based on some additional information. I don''t seem to be able to modify the value of a fact once it has been set. For example > > Facter.add("server_type") do > setcode do > "apache_web_server" > end > end > > # Later I may want to change the value. > > if Facter.value("http_server") = "false" > # Change value of "server_type" here. I have tried many different approaches but none work. > end > > Any advice would be greatly 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/-/AXcBrQsr4YsJ. > 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.________________________________ This message may contain confidential or privileged information. If you are not the intended recipient, please advise us immediately and delete this message. See http://www.datapipe.com/legal/email_disclaimer/ for further information on confidentiality and the risks of non-secure electronic communication. If you cannot access these links, please notify us by reply message and we will send the contents to you. -- 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.