Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm starting to configure systems using Puppet, and I'm having trouble with setting up my user account.

On our CentOS 5.3 server, the sudoers group is 'wheel', gid 10. On our Ubuntu 9.10 server, the group is 'sudo', gid 27. How do I setup the group account so that both boxes get the right group and my user is added to the right group?

I've tried splitting this config into os_vars.pp, virt_groups.pp, and virt_users.pp.

os_vars.pp:

class os_vars {
  case $operatingsystem {
    centos: {
      $os_admin_group = "wheel"
      $os_admin_group_gid = "10"
    }
    ubuntu: {
      $os_admin_group = "sudo"
      $os_admin_group_gid = "27"
    }
  }
  notice("in os_vars, admin group is: ${os_admin_group}, ${os_admin_group_gid}")
}

virt_groups.pp:

class virt_groups {
  include os_vars
  notice("in virt_groups, admin group is: ${os_admin_group}, ${os_admin_group_gid}")
  @group { $os_admin_group:
    gid => $os_admin_group_gid,
    ensure => present,
  }
}

virt_users.pp:

class virt_users {
  include os_vars
  notice("in virt_users, admin group is: ${os_admin_group}, ${os_admin_group_gid}")
  @user { 'my_user':
    home => '/home/my_user',
    uid => '500',
    groups => [$os_admin_group],
    password => $1BigLongEncrypedStuff
    gid => '500',
    ensure => 'present',
    shell => '/bin/bash'
  }
}

In os_vars.pp, the variables are set correctly, but they are empty in virt_users.pp and virt_groups.pp.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

The variables need to be scoped and quoted. The correct syntax for virt_groups.pp is:

class virt_groups {
  include os_vars
  notice("in virt_groups, admin group is: ${os_vars::os_admin_group}, ${os_vars::os_admin_group_gid}")
  @group { "${os_vars::os_admin_group}:
    gid => "${os_vars::os_admin_group_gid}",
    ensure => present,
  }
}

This solves my immediate problem, but still seems like a clunky way of handling what is probably a common puppet issue.

share|improve this answer
    
Please, do not add extra quotes around variables for no reason. "${os_vars::os_admin_group_gid}" is unnecessarily complex, $os_vars::os_admin_group_gid is fine. –  Mikko Jul 23 '13 at 13:37

As in previous answer, the variables must be scoped. Don't bother with group ID:s or virtual sudo/wheel groups. If the admin group is already present in the system, you don't have to define it.

Using the ? selector instead of case makes the code a bit less verbose:

class os_vars {
  $admin_group = $::operatingsystem ? {
     'centos' => 'wheel',
     default  => 'sudo',
  }
  notice("in os_vars, admin group is: ${admin_group}")
}

class virt_users {
  include os_vars
  notice("in virt_groups, admin group is: ${os_vars::admin_group}")
  @user { 'my_user':
    ....
    groups => [$os_vars::admin_group],
  }
}

If the group does not exist and you have to create it with Puppet, it's best to leave GID out to avoid collisions. system parameter gives the group an ID from system area:

include os_vars
group {$os_vars::admin_group:
  ensure => present,
  system => true,
}
share|improve this answer

Your Answer

 
discard

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.