Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 4 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,
) {
    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


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.