Collector, Overriding Params and undef vars

41 views
Skip to first unread message

William Leese

unread,
Jan 17, 2014, 3:21:06 AM1/17/14
to puppet...@googlegroups.com
Hi,

I had a nice setup where I'd load a hash of from hiera as virtual resources. These would be considered defaults that could be overridden through a defined type. The defined type would allow things like homedir and such to be overridden and the rest of the params would use the defaults as already set when declaring the virtual resource.

Suddenly someone discovered that this no longer worked. I'm pretty sure it did in the past though.

define userman_mw::users::virtualuser (
  $tagged         = undef,
  $account        = undef,
  $email          = undef,
  $groups         = undef,
  $uid            = undef,
  $shell          = undef,
  $homedir        = undef,
  $homemode       = undef,
  $manage_homedir = undef,
  $service        = false,
) {
  Userman_mw::Add_user <| $attribute == $value |> {
    email          => $email,
    groups         => $groups,
    uid            => $uid,
    shell          => $shell,
    homedir        => $homedir,
    homemode       => $homemode,
    manage_homedir => $manage_homedir,
  }
}

This a snipped version of the define that allows overriding. In the past, when no overrides were provided, the collector seemed to interpret that as 'do not change whatever the param was initially declared as'. Now, despite being 'undef', these variables cause the declared parameters values to be set to nil.

William Leese

unread,
Jan 17, 2014, 3:39:16 AM1/17/14
to puppet...@googlegroups.com
code wise, I guess this boils down to:

@user{ 'wleese3':
  comment => "bleh",
  uid     => 9999,
}

User <| title == 'wleese3' |> { comment => 'blah', uid => undef }

where I used to rely on uid => undef resulting in 9999 being used.

jcbollinger

unread,
Jan 17, 2014, 9:22:43 AM1/17/14
to puppet...@googlegroups.com


If that ever worked for you as you think it did then that represented a Puppet bug.  The behavior does not correspond to current or any historic behavior of which I am aware.

Declaring a resource parameter to have the pseudo-value undef is an affirmative expression of not declaring any value for that parameter.  Resource parameter overrides, on the other hand, are more literal than that.  Overriding a parameter with undef is not an expression of not overriding that parameter at all; rather, doing so overrides the target resource declaration as if it had originally declared undef for the parameter in question.  That is, it overrides the original declaration as if it had not declared any value for the parameter.


John

William Leese

unread,
Jan 17, 2014, 6:59:40 PM1/17/14
to puppet...@googlegroups.com
makes perfect sense.

Attacking my problem from a different angle, without completely redesigning the module, how would one go about checking to see if multiple variables are defined and using only those that are defined as parameter overrides for a collector?


--
William Leese

William Leese

unread,
Jan 20, 2014, 9:27:56 PM1/20/14
to puppet...@googlegroups.com
Created a function that generates a collector. Will use a different function to remove all undef-ed values from a hash and feed that to the fuction:

Reply all
Reply to author
Forward
0 new messages