Ask Your Question

apply config depending on installed package

asked 2015-12-29 18:07:11 -0500

akleinow gravatar image

I have multiple linux servers running two different openssh packages. This is by design. I want to write a puppet module that applies the correct configuration based on which package is installed. How can I do this without puppet trying to install the package that's not present?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-12-30 18:36:39 -0500

GregLarkin gravatar image

I'm not sure if this is possible in your environment or not, but it would be better if Puppet managed the openssh packages for you and installed one vs. the other depending on some condition, e.g. OS version, system type, etc. Based on that condition, you can then also perform other configuration as needed.

Your code might look like:

$servertype = hiera_lookup_or_other_function_call_here()

if ($servertype == 'type1') {
  $openssh_pkg = 'openssh-std'
} else {
  $openssh_pkg = 'openssh-extra'

package { $openssh_pkg:
  ensure => present,

# Do other configuration as needed...

If you want to stick with unmanaged openssh packages, then you will have to write a custom fact that presents the name of the currently-installed openssh package to the Puppet master. Then you can write some code that performs configuration based on the openssh package that has been previously installed and is not part of the Puppet configuration.

The easiest way to achieve that would to use this Puppet Forge module:

I haven't tested it, but I think you could then write some code that looks like this:

resource_facts::resource { 'package': }

Then your agent nodes should present a large, structured fact to the Puppet master containing a list of all installed packages. Your code will then have to index into that fact to figure out which openssh package is present and apply further configuration to the node based on the answer.

Hope this helps!

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: 2015-12-29 18:07:11 -0500

Seen: 69 times

Last updated: Dec 30 '15