Ask Your Question

question on included classes with parameters

asked 2018-01-23 13:55:10 -0600

onealdw gravatar image

updated 2018-01-24 10:51:31 -0600

DarylW gravatar image

I am running puppet 4.10.7 under foreman and have an issue with including declared classes under other classes. In particular, I have the puppet/yum module installed and am using it to define a set of yum repositories that will be installed for all systems. Now I want to define another class that will be applied to a subset of those systems and I need a yum repository defined only for those systems. I have tried multiple solutions, none of which work, What I'd like to do is in my init.pp have

 class batch ( $repo=false) {
     include yum    if ($repo) {
     yum::managed_repos($repo)   } }

This obviously does not work to install the repository file. What would work in this case?

edit retag flag offensive close merge delete



I think I'm still unclear on what you are trying to do... In puppet, you can only instantiate a single version of a class. If you declare the same class with different parameters, that is syntactically incorrect and your catalog will fail to compile

DarylW gravatar imageDarylW ( 2018-01-24 10:55:37 -0600 )edit

If you have a set of repos, with a specific subset under it, your only option is to either make two classes, or make a single class aware of the subset, and pass the parameters to it. In one case you're duplicating some code for readability/separation of concerns, in the other you are coupling ...

DarylW gravatar imageDarylW ( 2018-01-24 10:57:09 -0600 )edit

... the two ideas together into a single class with some internal logic to apply different configurations to the internal parts, but that may make more sense for your org.

DarylW gravatar imageDarylW ( 2018-01-24 10:57:51 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-05-04 05:31:06 -0600

No, you have to use resource-like class declarations in order to define class parameters (inside your Puppet manifest). That means, you have build expressions evaluating to the proper class parameter's value:

class batch (
  Optional[Array[String[1], 1]] $repo = undefined,
) {
  class { 'yum':
    managed_repos => $repo,

I don't know whether the +> “plusignment” works on classes, too.

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: 2018-01-23 13:55:10 -0600

Seen: 253 times

Last updated: May 04