Ask Your Question

New to Puppet. How do you use facts in modules in puppet 5?

asked 2017-07-27 15:53:44 -0600

RizzMattiz gravatar image

I'm trying to use a facter fact in puppet 5 to determine a package version to install.

I tried using this fact os.release.major in a if statement so:

if ::os.release.major == '7' { } .

Im not exactly sure what the correct syntax is.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2017-08-02 16:41:50 -0600

eric aldinger gravatar image

Facts are part of the mysterious eco system in Puppet, at least to me.

There are node facts and custom facts. Assuming you are wanting to use details about the node under management, based on OS differences. A simplified (nonworking) example is a module to install firefox. We would want this to work on different OSs but the commands would be different.

if $facts['os']['family'] == 'redhat' { # yum install firefox commands }

if $facts['os']['family'] == 'ubuntu' { # apt install firefox commands }

One thing to not is that the node knows what OS it has on it because facter added that info. You do not need to do anything for that OS fact to be present. A simple test of this on a node is to type

facter os

edit flag offensive delete link more

answered 2017-07-29 06:53:37 -0600

Why don't you consult the documentation, eh?

PP doc: facts and builtin variables § accessing facts from PP code

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

1 follower


Asked: 2017-07-27 15:53:44 -0600

Seen: 131 times

Last updated: Aug 02 '17