Ask Your Question
0

How can I set var to undef that has a default value in class/define?

asked 2016-04-23 16:32:21 -0500

erikanderson753 gravatar image

updated 2016-04-23 16:36:33 -0500

On puppet 4.4.1 I set up the following test:

class testingclass(
  $cmd_path = 'PluginDir',
){
  $message_ntfy = "cmd_path is set to: ${cmd_path} for ${name}"
  notify { $message_ntfy: }
}

define testingdefine(
  $cmd_path = 'PluginDir',
){
  $message_ntfy = "cmd_path is set to: ${cmd_path} for ${name}"
  notify { $message_ntfy: }
}

node default {

  class {'testingclass':
    cmd_path => undef,
  }

    testingdefine { 'testingdefinedefaults': }
    testingdefine { 'testingdefineundef':
      cmd_path => undef,
    }
}

I expect the class and testingdefine undef have cmd_path set to undef but instead they all pick up the default value:

erik.anderson@puppetmaster1:~$ sudo puppet apply test.pp
Warning: Config file /etc/puppetlabs/code/hiera.yaml not found, using Hiera defaults
Notice: Compiled catalog for sa-sand-puppetmaster1.sa.moneydesktop.com in environment production in 0.20 seconds
**Notice: cmd_path is set to: PluginDir for testingclass**
Notice: /Stage[main]/Testingclass/Notify[cmd_path is set to: PluginDir for testingclass]/message: defined 'message' as 'cmd_path is set to: PluginDir for testingclass'
**Notice: cmd_path is set to: PluginDir for testingdefinedefaults**
Notice: /Stage[main]/Main/Node[default]/Testingdefine[testingdefinedefaults]/Notify[cmd_path is set to: PluginDir for testingdefinedefaults]/message: defined 'message' as 'cmd_path is set to: PluginDir for testingdefinedefaults'
**Notice: cmd_path is set to: PluginDir for testingdefineundef**
Notice: /Stage[main]/Main/Node[default]/Testingdefine[testingdefineundef]/Notify[cmd_path is set to: PluginDir for testingdefineundef]/message: defined 'message' as 'cmd_path is set to: PluginDir for testingdefineundef'
Notice: Applied catalog in 0.35 seconds

I tested this on puppet 4.4.0 and 3.8.6 with the same results. Is there something with my test, is this expected behavior, or could this be a bug?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-04-24 01:34:19 -0500

I assumed this was the expected behaviour, and in fact I rely on it here in one of my modules.

edit flag offensive delete link more

Comments

Do you think there is a way to pass undef in a way that it overrides the class/define default?

erikanderson753 gravatar imageerikanderson753 ( 2016-04-24 18:36:57 -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: 2016-04-23 16:32:21 -0500

Seen: 106 times

Last updated: Apr 24 '16