About | FAQ | Help
Ask Your Question

How retrieve a fact and store this value in a variable with Puppet?

asked 2016-08-03 09:17:12 -0500

Edely gravatar image

I have a script where I retrieve the IP from a machine and then perform some logical operations to decide what value give to a variable. Then I use this value to make some decisions about the environment the machine is working.

I am trying to translate this to Puppet, but I am not shure how to proceed. I know I can retrieve the IP using facts, but should I do this in an manifest or a template. Also where should I perform the logical operations. Have in mind I'm going to do string manipulation.

To summerize, these are the steps I have to take.

1) Get the IP from the machine.

2) Perform logical operations.

3) Pass a variable with the result to a manifest.

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-08-03 16:48:55 -0500

DarylW gravatar image

It depends on what you are trying to do, your usecase sounds like the following..

Your IP addresses belong to specific subnets.. Given that it matches a particular subnet, you know it is in the X region as opposed to the Y region Configure part of your system that has region specific information.

In a case similar to that, the way that most people procede is to not do the logic directly in puppet. You would create a custom fact that can boil down the single piece of information for you (region/datacenter/ test/prod/dev/qa staging env, etc..)

I would recommend looking though https://docs.puppet.com/facter/3.1/cu... to learn about writing custom facts. You would use that information (getting the current IP address by referencing the ipaddress fact, etc..), figure out the bits you need (case statement/regex matchers or something), and then return a value for the fact that you can use to key other configuration off of later.

edit flag offensive delete link more


Thanks. This is exactly what I am trying to do. I going take a look in the approach you recommended.

Edely gravatar imageEdely ( 2016-08-04 05:20:01 -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

1 follower


Asked: 2016-08-03 09:17:12 -0500

Seen: 118 times

Last updated: Aug 03 '16