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

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 -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