Ask Your Question
0

different default values in params based on a parameter?

asked 2015-10-23 15:45:41 -0500

tsheriffk gravatar image

For some reason I cannot see the obvious answers staring back at me, so i am going to toss it out here..

quick back story- In my org, we only own the "get the platform configured" part of system configuration and not anything to do with the actual install of the application on the system. With that, we have different requirements based on the application type that will be running on the system. This includes the application role account, its uid/gid, proc limits ect in order to prepare the platform so they can deploy their application..

I have a functioning module to do this, where we (using foreman) set the role_user variable to something like tomcat, pentaho etc... However in adding in some functionality, I am trying to make the clean up the module / rewrite it a bit...

My issue is what is the best way to do this..

Is there a way to use the params.pp file based on a parameters value to give different defaults (where role_user is defined in the init.pp and possibly overridden by foreman)?

ie

   class app_type::params {
      $source_base = "puppet:///modules/${module_name}/"

      case $role_user {
         'appadm' : {
                 $role_user_group = 'appadm'
                 $role_user_uid_default = '1302'
                 $role_user_gid_default = '1302'
                 $role_user_home_default = '/home/appadm'
                 $role_user_comment_default = 'Application Administrator Role'
                 $role_user_shell_default = '/bin/bash'
                 $file_limits_default = '4096'
                 $proc_limits_default = 'undef'
          }
          'tomcat' : {
                 $role_user_uid_default = '1301'
                 $role_user_gid_default = '1301'
    <snip>

I am pretty sure the answer is no, that the params.pp things need to be derived from facts that are already known...

But what I can't seem to come up with in my head, is what is the best way to achieve a similar result? Does anyone have any thoughts that can kick me into the right direction?

Or am I overthinking this and it is best just to stick with a separate class for each item that I am trying to have as an option in my "case" statement?

thx!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-10-26 04:30:28 -0500

Cristian Falcas gravatar image

updated 2015-10-26 10:41:35 -0500

Well, since you are using foreman, you have access to a global fact named $::hostgroup. This will be the name of the hostgroup assigned to the host.

Edit

Since you can't use hostgroup fact, you need to rethink your module: it will not work the way you designed it now, due to the fact that params class will be parsed before entering in the init class. So any variable that will be passed to the main class will not be available to params class.

Short story: if you want to send a parameter to your main class from which you want to decide what parameters to use, you need to move all your logic from params to the main class.

Or not inherit the params class in main class and just include it there. This way you lose all the overwrites and defaults that came with the pattern of using the params class.

edit flag offensive delete link more

Comments

that is true, however without going into it we aren't yet really using hostgroups right now due to a previous issue on our part in doing so. I know that we should be using them and will be again eventually.

tsheriffk gravatar imagetsheriffk ( 2015-10-26 09:26:22 -0500 )edit

That is what I was afraid of (and how it is currently setup).. We currently use a lot of USE_DEFAULTS as the values for parameters, so adding more parameters to the manifest is going to make it longer than i'd like... but it is what it is.... thanks for the input and ideas!

tsheriffk gravatar imagetsheriffk ( 2015-10-28 09:31:44 -0500 )edit

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

Stats

Asked: 2015-10-23 15:45:41 -0500

Seen: 527 times

Last updated: Oct 26 '15