Ask Your Question

What's the preferred way of geo-locating an agent node?

asked 2013-01-10 03:46:58 -0500

fghaas gravatar image

updated 2013-01-10 03:51:14 -0500

Suppose, for the sake of argument, I managed a globally distributed infrastructure making heavy use of Debian. I'd like for each of my machines to be able to use the local Debian mirror as its apt repository source.

What I would ideally like to be able to do is

  • determine the IP address that my agent uses to hit my puppetmaster (possibly NATed IPv4, hence unrelated to the $ipaddress fact if I understand the implications of the latter correctly),
  • then use a custom function to wrap a GeoIP lookup library (possibly geoip) to determine the node's country,
  • stick ...
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-01-10 15:31:17 -0500

fghaas gravatar image

updated 2013-01-11 05:08:22 -0500

Thanks Joe. Thanks in particular for pointing me to facter-dot-d, which in combination with a JSON capable geoip service actually makes this really easy.

class location ( $url = "", $filename = "location.json" ) {

  exec { "wget -q $url -O /etc/facter/facts.d/$filename":
    creates => "$/etc/facter/facts.d/$filename",
    path => ["/bin", "/sbin", "/usr/bin", "/usr/sbin"]

The use of creates ensures that we do this only once per node. You can obviously polish this to make sure that the directory exists, etc., but the snippet above illustrates the concept. And as long as the json gem (or ruby-json or ... (more)

edit flag offensive delete link more


That's really slick. :)

jtopjian gravatar imagejtopjian ( 2013-01-10 16:29:29 -0500 )edit

There's now a module for this on the Forge at

fghaas gravatar imagefghaas ( 2013-01-13 15:58:11 -0500 )edit

answered 2013-01-10 11:02:56 -0500

jtopjian gravatar image

updated 2013-01-10 11:03:30 -0500

Hi Florian,

If the use-case is specific to just apt-mirrors, you could create a shell script that runs something like netselect-apt or apt-spy. Then execute that script through an exec resource and only have it run if a control file such as /var/lib/apt/dont-run-me doesn't exist. You could do this on each node or designate a single server at each location to be an apt-cacher server and have all nodes at each location connect to the designated server.

To expand the use-case to account for other location-based scenarios, one way to do this is to create a ... (more)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-01-10 03:46:58 -0500

Seen: 289 times

Last updated: Jan 11 '13