scheduling defined resources

43 views
Skip to first unread message

Mark deJong

unread,
Mar 7, 2014, 2:57:58 PM3/7/14
to puppet...@googlegroups.com
Hello,
We're currently using version 3.4.3, and the documentation on metaparameters states "any defined metaparameter can be used with any instance in your manifest, including defined components." Unless I'm missing something, this statement does not hold true to the schedule parameter which gets passed into the defines as variables. Is there anyway to change its behavior to apply the schedule to our custom defines as a whole, and not have to pass that parameter to every resource within?

Thanks!
M

jcbollinger

unread,
Mar 10, 2014, 1:47:22 PM3/10/14
to puppet...@googlegroups.com


On Friday, March 7, 2014 8:57:58 AM UTC-6, Mark deJong wrote:
Hello,
We're currently using version 3.4.3, and the documentation on metaparameters states "any defined metaparameter can be used with any instance in your manifest, including defined components." Unless I'm missing something, this statement does not hold true to the schedule parameter which gets passed into the defines as variables.


What makes you say that?  Do you have a manifest that seems to contradict that statement, and http://docs.puppetlabs.com/puppet/latest/reference/lang_defined_types.html#metaparameters ?

 
Is there anyway to change its behavior to apply the schedule to our custom defines as a whole, and not have to pass that parameter to every resource within?



As I read the docs, you shouldn't need to do anything special to achieve that.  Suppose you present the manifest(s) that is causing you trouble, and maybe we can shed some more light on the problem.


John

Mark deJong

unread,
Mar 11, 2014, 12:08:45 PM3/11/14
to puppet...@googlegroups.com


On Monday, March 10, 2014 9:47:22 AM UTC-4, jcbollinger wrote:


On Friday, March 7, 2014 8:57:58 AM UTC-6, Mark deJong wrote:
Hello,
We're currently using version 3.4.3, and the documentation on metaparameters states "any defined metaparameter can be used with any instance in your manifest, including defined components." Unless I'm missing something, this statement does not hold true to the schedule parameter which gets passed into the defines as variables.


What makes you say that?  Do you have a manifest that seems to contradict that statement, and http://docs.puppetlabs.com/puppet/latest/reference/lang_defined_types.html#metaparameters ?

 I'm having the issue with the passwd::user accepting the schedule metaparameter. I have tried it both with and without define the variable 'schedule.'

class passwd (
  $module_path        = $passwd::params::module_path,
  $path               = $passwd::params::path,
  $alg                = $passwd::params::alg,
  $length             = $passwd::params::length,
  $plugin             = $passwd::params::plugin,
  $enotify            = $passwd::params::enotify,
  $esubject           = $passwd::params::esubject,
  $schedule           = $passwd::params::schedule,
  $managehome         = $passwd::params::managehome,
  $homeowner_override = $passwd::params::homeowner_override,
  $homeowner          = $passwd::params::homeowner,
  $homegroup          = $passwd::params::homegroup,
  $users       = [],
) inherits passwd::params {
  include passwd::virtual

  validate_absolute_path($module_path)
  validate_absolute_path($path)
  validate_string($alg)
  validate_array($enotify)
  validate_string($esubject)
  validate_array($users)
  validate_bool($managehome)
  validate_bool($homeowner_override)

  anchor {'passwd::begin': } ->
  class {'passwd::install': } ->
  class {'passwd::schedule': } ->
  class {'passwd::provision': } ->
  anchor {'passwd::end': }
}


define passwd::user (
  $password,
  $uid,
  $gid,
  $comment,
  $shell,
  $home               = "${passwd::home_root}/${name}",
  $managehome         = $passwd::managehome,
  $homeowner_override = $passwd::homeowner_override,
  $homeowner          = $passwd::homeowner,
  $homegroup          = $passwd::homegroup,
  $path               = $passwd::path,
  $length             = $passwd::length,
  $ensure             = $passwd::ensure,
  $plugin             = $passwd::plugin,
  $enotify            = $passwd::enotify,
  $esubject           = $passwd::esubject,
  $schedule           = undef
){
  if ($password == 'G' and $ensure == 'present') {
    $pclear = generate('/bin/sh','-c',"/bin/cat  /dev/urandom | /usr/bin/tr -dc 'a-zA-Z0-9' | /usr/bin/fold -w ${length} | /usr/bin/head -n 1| tr -d '\n'")
    $pcrypt = generate('/usr/bin/openssl','passwd','-1',"'${pclear}'")
    $rpassword = chomp("${pcrypt}")
    notify {"${rpassword}":}
    if ! empty($enotify) {
      passwd::notify { $name:
        enotify  => $enotify,
        username  => $name,
        password => $pclear
      }
    }
  }
  else {
    $rpassword = $password
  }
  Augeas {
    load_path => "${passwd::params::module_path}/auglenses",
    lens   => "PluginPasswd.lns",
    incl    => "${path}",
  }
  case $ensure {
    present: {
      augeas { "pw_pl_mod_${name}":
        changes => [
          "set ${name}/password '${rpassword}'",
          "set ${name}/uid '${uid}'",
          "set ${name}/gid '${gid}'",
          "set ${name}/name '${comment}'",
          "set ${name}/home '${home}'",
          "set ${name}/shell '${shell}'",
        ],
schedule => $schedule
      }
      if $managehome {
        file { $home:
          ensure  => directory,
          owner   => homeowner_override ? {
            true    => $homeowner,
            default => $uid
          },
          group   => homeowner_override ? {
            true    => $homeowner,
            default => $gid
          },
          seltype  => user_home_dir_t,
          require => File[$passwd::home_root]
        }
      }
    }
    absent: {
      augeas { "pw_pl_mod_${name}":
        changes => [
          "rm ${name}"
        ]
      }
    }
  }


class passwd::schedule (

) inherits passwd {
  schedule { 'passwd_generate_monthly':
    period => monthly,
    range  => "2 - 4",
    repeat => 1
  }
}


When I call passwd::user as either a resource or virtual resource, schedule is only honored by puppets built in functions within my define, but not  by passwd::user.

class passwd::virtual(
) inherits passwd {

  passwd::user{ 'johnjackson':
    password => "supersecretpassword",
    uid      => 121,
    gid      => 121,
    comment  => "User Comment",
    shell    => "/bin/false",
    schedule => 'passwd_generate_monthly'
  } 

  @passwd::user{ 'jimbeam':
    password => "G",
    uid      => 121,
    gid      => 121,
    comment  => "User Comment",
    shell    => "/bin/false",
    schedule => 'passwd_generate_monthly',
  }
}

Thanks!
M

jcbollinger

unread,
Mar 12, 2014, 1:27:24 PM3/12/14
to puppet...@googlegroups.com


On Tuesday, March 11, 2014 7:08:45 AM UTC-5, Mark deJong wrote:

 I'm having the issue with the passwd::user accepting the schedule metaparameter. I have tried it both with and without define the variable 'schedule.'



The thing that jumps out at me right away is that you are declaring your own $schedule parameter to your class and defined type.  All Puppet classes and resource types, including defined types, have that [meta]parameter automatically, without you declaring it.  It may be that by declaring it explicitly you are shadowing the metaparameter with an ordinary parameter of the same name.

Additionally,
  • class passwd::schedule should not inherit from class passwd.  It yields no benefit whatsoever for the code presented, and it creates a circular evaluation dependency involving those two classes (which Puppet nevertheless seems to handle successfully).
  • a schedule has no effect of its own on catalog application, therefore it is useless (but also harmless) to include class passwd::schedule in your relationship chain.  It would be sufficient to just declare it without chaining.

John

Felix Frank

unread,
Mar 12, 2014, 1:39:45 PM3/12/14
to puppet...@googlegroups.com
To answer the original point - no, I disbelieve you can tell puppet to
automagically pass certain metaparameters on to all contained resources.

That would be a useful feature I think.

Note that there is at least one pertinent bug report at
https://projects.puppetlabs.com/issues/12653

...but I believe you have nailed the issue better than the OP, actually.

Mark deJong

unread,
Mar 12, 2014, 6:22:39 PM3/12/14
to puppet...@googlegroups.com


On Wednesday, March 12, 2014 9:27:24 AM UTC-4, jcbollinger wrote:


On Tuesday, March 11, 2014 7:08:45 AM UTC-5, Mark deJong wrote:

 I'm having the issue with the passwd::user accepting the schedule metaparameter. I have tried it both with and without define the variable 'schedule.'



The thing that jumps out at me right away is that you are declaring your own $schedule parameter to your class and defined type.  All Puppet classes and resource types, including defined types, have that [meta]parameter automatically, without you declaring it.  It may be that by declaring it explicitly you are shadowing the metaparameter with an ordinary parameter of the same name.

I thought that initially as well, and had tested removing my declared $schedule previously. Just to be sure I have removed all references of my own 'schedule' parameter again and it still yields the same results. I'll try to reproduce the bug report referenced by Felix.Frank.
 
Additionally,
  • class passwd::schedule should not inherit from class passwd.  It yields no benefit whatsoever for the code presented, and it creates a circular evaluation dependency involving those two classes (which Puppet nevertheless seems to handle successfully).
  • a schedule has no effect of its own on catalog application, therefore it is useless (but also harmless) to include class passwd::schedule in your relationship chain.  It would be sufficient to just declare it without chaining.
Thanks for the additional feedback! ;)

 

John

jcbollinger

unread,
Mar 12, 2014, 10:25:14 PM3/12/14
to puppet...@googlegroups.com


On Wednesday, March 12, 2014 8:39:45 AM UTC-5, Felix.Frank wrote:
To answer the original point - no, I disbelieve you can tell puppet to
automagically pass certain metaparameters on to all contained resources.


Felix Frank

unread,
Mar 13, 2014, 2:24:03 PM3/13/14
to puppet...@googlegroups.com
On 03/12/2014 11:25 PM, jcbollinger wrote:
> To answer the original point - no, I disbelieve you can tell puppet to
> automagically pass certain metaparameters on to all contained
> resources.
>
>
> Well, you can't /tell it/ to do so, but see
> http://docs.puppetlabs.com/puppet/latest/reference/lang_defined_types.html#metaparameters.

Oh god. Looks like my knowledge of those things was frozen in the 2.6 or
earlier era. Thanks for the update.

Cheers,
Felix
Reply all
Reply to author
Forward
0 new messages