Hi Dan,

variables in classes are always local variables.
You can reference variables from other classes by adding the namespace 
(classname) to the variable.
Referencing variables from other classes is only possible when the class 
containing the variables has been declared:

class adduser::user_ray {
  require adduser::config
  user { 'bob':
    ensure      => 'present',
    comment  => 'Bob User',
    gid            => $adduser::config::staffgid,
    home        => '/home/bob',
    password => '*',
    shell         => $adduser::config::tcsh,
    uid           => '20049',
    managehome => true
  }
}



> On 4. Jun 2018, at 23:24, Dan Mahoney <gushimailt...@gmail.com> wrote:
> 
> Hey all,
> 
> We have a simple adduser module, with an init.pp like so:
> 
> class adduser::config {
>    case $facts['operatingsystem'] {
>      'Debian': {
>        $bash = '/bin/bash'
>        $tcsh = '/bin/csh'
>        $sh = '/bin/sh'
>        $staffgid = '50'
>        $wheelgroups = ['adm', 'sudo']
>        $rootgroup = 'root'
>      }
>      default: {
>        $bash = '/usr/local/bin/bash'
>        $csh = '/bin/csh'
>        $tcsh = '/bin/csh'
>        $sh = '/bin/sh'
>        $staffgid = '20'
>        $wheelgroups = ['wheel']
>        $rootgroup = 'wheel'
>      }
>    }
> }
> 
> This code *was* in the main "adduser" class, but we found that when we called 
> a user directly, it didn't run.
> 
> All our users have stanzas like this one:
> 
> class adduser::user_ray {
> require adduser::config
>   user { 'bob':
>     ensure   => 'present',
>     comment  => 'Bob User',
>     gid      => $staffgid,
>     home     => '/home/bob',
>     password => '*',
>     shell    => $tcsh,
>     uid      => '20049',
>     managehome => true
>   }
> }
> 
> Even with the direct require of adduser::config we still see errors like this 
> in the puppetserver log:
> 
> 2018-06-04 03:27:24,369 WARN  [qtp1220040994-783] [puppetserver] Puppet 
> Unknown variable: 'tcsh'. at 
> /usr/local/etc/puppet/code/environments/production/modules/adduser/manifests/init.pp:249:17
> 2018-06-04 03:27:24,377 WARN  [qtp1220040994-783] [puppetserver] Puppet 
> Unknown variable: 'staffgid'. at 
> /usr/local/etc/puppet/code/environments/production/modules/adduser/manifests/init.pp:460:17
> 2018-06-04 03:27:24,380 WARN  [qtp1220040994-783] [puppetserver] Puppet 
> Unknown variable: 'wheelgroups'. at 
> /usr/local/etc/puppet/code/environments/production/modules/adduser/manifests/init.pp:461:17
> 2018-06-04 03:27:24,382 WARN  [qtp1220040994-783] [puppetserver] Puppet 
> Unknown variable: 'bash'. at 
> /usr/local/etc/puppet/code/environments/production/modules/adduser/manifests/init.pp:464:17
> 
> What's the proper way to do this inheritance?  And the proper way to name 
> variables so they scope right?
> 
> Thanks in advance,
> 
> -Dan 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-users/801c1a76-75e0-4cc7-a7ee-8c7262c3ca70%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/EC2CB0E7-DB25-4413-B38F-01D4623C0B12%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to