Ask Your Question
0

question on included classes with parameters

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

onealdw gravatar image

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

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

Comments

1

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 -0500 )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 -0500 )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 -0500 )edit

1 Answer

Sort by » oldest newest most voted
1

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

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

Stats

Asked: 2018-01-23 13:55:10 -0500

Seen: 251 times

Last updated: May 04