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+unsubscr...@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.