Ask Your Question
0

override parameters using inherits

asked 2014-03-30 16:00:50 -0600

updated 2014-03-30 16:03:07 -0600

I am having trouble trying to overwrite parameters from my ssh module

I have a module with this class

   class labs-ssh::server($port_ssh=2828,$permit_root='no') {

      include labs-ssh
      $packages_ssh = hiera_array('packages_ssh')
      $service_ssh  = hiera('service_ssh')

        file {'sshd_config':
            ensure  => present,
            path    => '/etc/ssh/sshd_config',
            owner   => 'root',
            group   => 'root',
            mode    => 0644,
            content => template('labs-ssh/sshd_config.erb'),
            require => Package["$packages_ssh"],
            notify  => Service["$service_ssh"],
        }
    }

and I have a class for a base linux in my manifest when I declare this module for all linux machines.

class linux-server {

  include labs-base-utils
  include general-users   
  include labs-ssh::server

}

in my site.pp I declare this class linux-server for a ... (more)

edit retag flag offensive close merge delete

Comments

1

Is there a reason why $package_ssh and $service_ssh are hiera backed while $port_ssh and $permit_root are not?

ffrank gravatar imageffrank ( 2014-04-02 02:59:34 -0600 )edit

ffrank I was an idiot I totally forgot that I could use port_ssh and permit_root from hiera from a common.yaml and if I need a host specific using a ...(more)

Renan Vicente gravatar imageRenan Vicente ( 2014-04-02 07:25:34 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2014-04-02 07:31:00 -0600

updated 2014-04-02 08:11:44 -0600

Thank you ffrank and Mark Alfke to remember me that if I am already using hiera I could use hiera to solve this problem either.

I will post here as answer for history because both was comment.

I put in common.yaml a default value for my portssh and permitroot and for the hosts that I need different values I just create another yaml based on %{::fqdn} because fqdn have priority of common.

edit flag offensive delete link more

Comments

Probably my bad for convoluting my answer with too much context when this was actually my point. Cheers.

ffrank gravatar imageffrank ( 2014-04-02 08:09:39 -0600 )edit
0

answered 2014-03-31 06:46:48 -0600

updated 2014-03-31 06:49:08 -0600

Actual standard is to use params.pp with all parameters set (either do hiera calls implicitly [pre puppt 3] or let puppet look into hiera automatically [puppet 3.x] or use the main init.pp class with explicit parameters) and use inheritance in init.pp file only.

e.g. Definition:

class lab_ssh::params (
  $port_ssh,
  $permit_root
){
...
}

class lab_ssh inherits lab-ssh::params {
...
}

Declaration:

using defaults

include lab_ssh

overwriting defaults

class { 'lab_ssh':
   $port_ssh => '222',
}

P.S. do not use '-' in class names.

edit flag offensive delete link more

Comments

Thanks for your help but I already tried that and doesn't work, you can see that in my question when I said. node /labs-host1/ inherits linux-base { class {'labs-ssh::server ...(more)

Renan Vicente gravatar imageRenan Vicente ( 2014-03-31 07:25:54 -0600 )edit

OK. Got it. When doing inheritance you have to overwrite the existing resource declaration. Better solution would be using roles and profiles. Overwriting an inherited resource: node /labs-host1/ inherits linux-base ...(more)

Martin Alfke gravatar imageMartin Alfke ( 2014-04-01 08:05:09 -0600 )edit

I feel compelled to repeat myself: This doesn't and currently cannot work for class parameters, because classes are **not** resources, despite all the shiny syntax that tries to make ...(more)

ffrank gravatar imageffrank ( 2014-04-02 02:58:47 -0600 )edit
1

I should have read your whole post..... since you are already using hiera: you can use hiera on the class parameters with defaults set and then use a node specific hiera configuration.

Martin Alfke gravatar imageMartin Alfke ( 2014-04-02 03:38:58 -0600 )edit
0

answered 2014-03-31 03:52:29 -0600

ffrank gravatar image

The idea of overriding parameters in inheriting nodes and classes is sound, but pertains to resource parameters only. Class parameters cannot ever be overridden.

The best way for solving the "one node has special needs problem" is to add hiera to your setup and retrieve the ssh port from there. Hiera excels at declaring defaults and excemptions. Seeing as you have hiera in production already, you should definitely go that route.

Failing that, you could refactor your ssh::server class to enable you to do this, but it's really the inferior solution:

class labs-ssh::server {
  $permit_root = 'no'
  $port_ssh=2828 ...
(more)
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

Stats

Asked: 2014-03-30 16:00:50 -0600

Seen: 4,557 times

Last updated: Apr 02 '14