I need to create a custom fact based on a parametric information (I need to get the IP of another machine knowing the hostname, the machine name could be different for different nodes so I need it parameteric and I recover the machine hostname from a hiera, but for the purpose of the question it could also be a data in the module definition). I''m installing a cluster and need to get the master IP and if I can set the hostname as a fixed known information the IP will be variable since I''m installing it in a cloud environment The custom facter code is: # master_ip.rb: # require ''facter'' if FileTest.exists?("/usr/bin/dig") cmd = sprintf(''/usr/bin/dig +short HERE_GOES_THE PARAMETRIC_HOSTNAME'') result = `#{cmd}` Facter.add("master_ip") do setcode { result } end end Any Idea on how to refer to a data present in the module like $master_hostname or a hiera hash like $master_info[''hostname''] Thanks -- 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.
Do you know this information when you set up the server ? If so, just create an appropriate "host" resource http://docs.puppetlabs.com/references/latest/type.html#host “Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.” Bill Waterson (Calvin & Hobbes) ----- Original Message ----- From: "Luca Gioppo" <lucagioppo@gmail.com> To: puppet-users@googlegroups.com Sent: Wednesday, August 28, 2013 4:58:00 AM Subject: [Puppet Users] passing hiera data to custom fact I need to create a custom fact based on a parametric information (I need to get the IP of another machine knowing the hostname, the machine name could be different for different nodes so I need it parameteric and I recover the machine hostname from a hiera, but for the purpose of the question it could also be a data in the module definition). I''m installing a cluster and need to get the master IP and if I can set the hostname as a fixed known information the IP will be variable since I''m installing it in a cloud environment The custom facter code is: # master_ip.rb: # require ''facter'' if FileTest.exists?("/usr/bin/dig") cmd = sprintf(''/usr/bin/dig +short HERE_GOES_THE PARAMETRIC_HOSTNAME'') result = `#{cmd}` Facter.add("master_ip") do setcode { result } end end Any Idea on how to refer to a data present in the module like $master_hostname or a hiera hash like $master_info[''hostname''] Thanks -- 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.
On Wednesday, August 28, 2013 3:58:00 AM UTC-5, Luca Gioppo wrote:> > I need to create a custom fact based on a parametric information (I need > to get the IP of another machine knowing the hostname, the machine name > could be different for different nodes so I need it parameteric and I > recover the machine hostname from a hiera, but for the purpose of the > question it could also be a data in the module definition). > > I''m installing a cluster and need to get the master IP and if I can set > the hostname as a fixed known information the IP will be variable since I''m > installing it in a cloud environment > > The custom facter code is: > > # master_ip.rb: > # > > require ''facter'' > > if FileTest.exists?("/usr/bin/dig") > cmd = sprintf(''/usr/bin/dig +short HERE_GOES_THE PARAMETRIC_HOSTNAME'') > result = `#{cmd}` > Facter.add("master_ip") do > setcode { result } > end > end > > > Any Idea on how to refer to a data present in the module like > $master_hostname or a hiera hash like $master_info[''hostname''] > >This is altogether the wrong approach. The datum you wish to evaluate is not a property of the node, but rather a property of its environment, therefore it is not a node fact. If you want the master IP to be a top-scope variable then it is possible to make it so without making it a node fact, though I think that would be a poor design choice. Instead, you should make it a class variable of some suitable class. Wherever you hang it, you can assign the value based on your looked-up hostname, using a custom function or perhaps the built-in generate() function. 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 are right is not a node fact but an "env" datum, so I developed a function that get me the IP address of a Hostname and assigned to a variable of the node. Thanks Luca Il giorno mercoledì 28 agosto 2013 15:41:10 UTC+2, jcbollinger ha scritto:> > > > On Wednesday, August 28, 2013 3:58:00 AM UTC-5, Luca Gioppo wrote: >> >> I need to create a custom fact based on a parametric information (I need >> to get the IP of another machine knowing the hostname, the machine name >> could be different for different nodes so I need it parameteric and I >> recover the machine hostname from a hiera, but for the purpose of the >> question it could also be a data in the module definition). >> >> I''m installing a cluster and need to get the master IP and if I can set >> the hostname as a fixed known information the IP will be variable since I''m >> installing it in a cloud environment >> >> The custom facter code is: >> >> # master_ip.rb: >> # >> >> require ''facter'' >> >> if FileTest.exists?("/usr/bin/dig") >> cmd = sprintf(''/usr/bin/dig +short HERE_GOES_THE PARAMETRIC_HOSTNAME'') >> result = `#{cmd}` >> Facter.add("master_ip") do >> setcode { result } >> end >> end >> >> >> Any Idea on how to refer to a data present in the module like >> $master_hostname or a hiera hash like $master_info[''hostname''] >> >> > > This is altogether the wrong approach. The datum you wish to evaluate is > not a property of the node, but rather a property of its environment, > therefore it is not a node fact. > > If you want the master IP to be a top-scope variable then it is possible > to make it so without making it a node fact, though I think that would be a > poor design choice. Instead, you should make it a class variable of some > suitable class. Wherever you hang it, you can assign the value based on > your looked-up hostname, using a custom function or perhaps the built-in > generate() function. > > > 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.