Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Take this wrapper around ssh_authorized_key for example:

define sshauthkeys::helper ($user,$ensure='present') {


        ssh_authorized_key { "puppet: ${name2} ${user}":
          ensure => $ensure,
          type => $ssh_keys["${name2}"]["type"],
          key => $ssh_keys["${name2}"]["key"],
          user => "${user}"
        }
}

Let's say I wanted to introduce support of the 'target' parameter for that resource type, I'd do something like:

define sshauthkeys::helper ($user,$ensure='present', $target='') {

The problem is, if I want to use the sensible default from puppet derived from $user 's homedir - and override it on fringe cases, I lose the benefit of the work done to set the default in all of the other circumstances.

Is there a way to optionally override the value without having to write two functions?

Better description of the issue:

define sshauthkeys::helper ($user,$ensure='present', $target='') {

    ssh_authorized_key { "puppet: ${name2} ${user}":
      // etc etc...
      target = $target 
      // ^--- Here, I'm forcing it to '' - how do I use the puppet 
      // built-in derivation, and only override optionally?
    }

}

share|improve this question

1 Answer 1

up vote 3 down vote accepted

In this case, setting target => undef is the same thing as not specifying it at all, so you can write your wrapper like this:

define sshauthkeys::helper ($user,
  $ensure='present',
  $target=undef
) {
    ssh_authorized_key { "puppet: ${name2} ${user}":
      ensure => $ensure,
      target => $target,
      type   => $ssh_keys["${name2}"]["type"],
      key    => $ssh_keys["${name2}"]["key"],
      user   => "${user}"
    }
}
share|improve this answer
    
I love you, lol. Thanks! #highFive –  thinice Aug 15 '13 at 16:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.