On Friday, November 29, 2013 5:46:11 AM UTC-6, cko wrote: > > Thanks, i think i got something here: > > Facter.add("ip_prodlan") do > confine :kernel => "Linux" > setcode do > Facter::Util::Resolution.exec("/sbin/ifconfig | /bin/grep > '20.20.\\|30.31.\\|200.30.80.\\|120.' | /bin/awk '{ print $2 }' | /bin/cut > -d':' -f2 | /usr/bin/head -n1") > end > end > >
I really think that's a sub-optimal approach. Facter is already providing all the facts you need for this job. You ought to be analyzing those instead of creating a new one. Here's an outline: 1. Obtain a list of all defined network interfaces for the target node by splitting the value of the $::interfaces fact around commas. 2. For each interface name test the value of the $::ipaddress_<interface_name> fact against the subnet mask(s) of interest. 3. Take appropriate action and/or return a result. That should ultimately be done in a custom function, but as I said, it could be prototyped via an inline template. > I'm currently using the custom fact to print the production LAN ip address > in /etc/motd . > It usually returns the correct value. But in some cases the "puppet agent > -t" command changes the file in a *different* way than "service puppet > restart" does. Any idea? > > If performing a catalog run via "puppet agent -t" exhibits inconsistent behavior then I have trouble believing that forcing one via "service puppet restart" is always consistent. Do note, by the way, that the latter is a rather rough way to force a catalog run -- if the agent is running in daemon mode then you can trigger an immediate catalog run by sending it SIGUSR1. Perhaps your interfaces are going up and down. If the key interface happens to be down when Facter runs then its IP address probably will not be reported by ifconfig, so you might not see any of the subnets you're looking for. > Another question: > > I want my custom fact to do something like this: > if the "Resolution.exec" returns 0 (nothing) then ip_prodlan should use > the value of the fact "$ipaddress". > Is it possible to do something like this? > > Probably, but don't. Perform this sort of test and data selection in your manifests, not in Facter. 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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/b3166eb0-3fc2-4688-ac78-ad5ff5dd6c4e%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.