Ask Your Question
0

creating 'location' fact

asked 2016-10-21 11:07:59 -0500

gene gravatar image

I'm relatively new to puppet and have a puppet server up and some agents deployed on some test nodes. We have servers in two different locations (at a colo facility and on campus). I'd like to be able to take actions in some of my classes based off of the location (e.g. either 'colo' or 'campus'). I can determine the location based upon the server IP address but i'm not sure how to actually put that into practice.

I'm reading up on hiera but definitely don't have my head wrapped around that yet. I'm thinking that I should somehow define in hiera the list of subnets in use in each of the two locations and associate those with the correct location.

For example, if my subnet to location mapping is this:

192.168.1.0/24, 192.168.2.0/24 => location = colo
192.168.3.0/24, 192.168.4.0/24 => location = campus

I'm not sure how to translate that into something useable inside my common.yaml. My common.yaml (/etc/puppetlabs/code/hieradata/common.yaml) currently looks like this:

#common.yaml
---
ntp::autoupdate: true
ntp::enable: true
ntp::servers:
  - tick.gatech.edu

profile::puppet::runinterval: 600

How would I code that in common.yaml? Is this the best way to determine 'location' of a node? Any help is most appreciated.

Gene

edit retag flag offensive close merge delete

Comments

Location mapping should be made via your network switches, not via IP-addresses. Where your computers are wired determine their location, not their addresses.

Kai Burghardt gravatar imageKai Burghardt ( 2016-10-21 18:15:06 -0500 )edit

Thanks for the comment Kai. I was looking to determine the location of my nodes and the easiest way I could think of to do that was based upon the node's IP address. Based upon the subnet the node resides in, I can then set the appropriate root password. That was my goal.

gene gravatar imagegene ( 2016-10-24 09:50:10 -0500 )edit

Ah, OK, in that case, the approach lavaman suggested is sufficient.

Kai Burghardt gravatar imageKai Burghardt ( 2016-10-24 16:25:15 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-10-21 13:37:19 -0500

lavaman gravatar image

updated 2016-10-21 13:37:46 -0500

You wouldn't put that in your common.yaml. You would create new hiera files for each location with the appropriate values and put that into your hiera config.

As far as determining the location from IP, you can either write a custom fact or you can just put some logic in your site.pp that sets a global variable (which hiera can also use like fact values).

Site.pp is the easier way (doesn't require ruby code):

    if $::ipaddress =~ /^192\.168\.[1,2]/ {
      $location = colo
    } else {
      $location = campus
    }

If you have or add more subnets, you can also do an elsif with another regex.

edit flag offensive delete link more

Comments

Thanks lavaman! I did as you suggested in site.pp to set the location. I then used that in a profile::common::root class to set the root password based on the location. We use a different root password for our colo servers.

gene gravatar imagegene ( 2016-10-24 09:45:46 -0500 )edit

With a custom fact to output your location, you would be able to add a 'location' tier in your hiera config, and put the specific configuration in a hieradata/location/colo.eyaml (for passwords) and a campus.eyaml for your other locations, and there you store your 'location' specific information

DarylW gravatar imageDarylW ( 2016-10-24 10:54:50 -0500 )edit

That works whether it's a global var from site.pp or a custom fact.

lavaman gravatar imagelavaman ( 2016-10-24 12:39:08 -0500 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2016-10-21 11:07:59 -0500

Seen: 52 times

Last updated: Oct 21 '16