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

Mostly as a learning exercise, I'm trying to use defines to create users. There are no errors, but the user doesn't get created. Adding calls to notify makes me suspect the problem is the order of execution (but it may also be my newbness elsewhere). I'm using Puppet 2.7.9.

Here's my code.

    # manifests/nodes.pp
    node /song.*/ {
      include users
      User <| group == developers |>
    }

    # modules/users/manifests/init.pp
    class users {
      include users::people
    }

    # modules/users/manifests/people.pp 
    class users::people {
      require groups
      @users::account { "michael":
          username => "michael",
          name     => "Michael C. Harris",
          uid      => 1000,
          gid      => "developers",
          password => '{encrypted password}',
          groups   => [ "wheel" ],
      }
    }

    # modules/groups/manifests/init.pp
    class groups {
      Group { ensure => present }
      group { "wheel":
        gid => 10;
      }
      group { "developers":
        gid => 1001;
      }
    }

    # modules/users/manifests/account.pp
    define users::account($ensure=present, managehome='true', allowdupe='false', homeprefix='/home', $username, $name, $password, $uid, $gid, $groups=[], $key='', $keytype='ssh-rsa', shell='/bin/zsh') {

      File { owner => $username, group => $username, mode => '0600' }

      $home = "${homeprefix}/${username}"

      user { $username:
        ensure     => $ensure,
        uid        => $uid,
        gid        => $gid,
        password   => $password,
        comment    => "$name",
        groups     => $groups,
        shell      => "$shell",
        home       => $home,
        require    => Group["$gid"],
        allowdupe  => $allowdupe,
        managehome => $managehome;
      }

      file { "$home":
        ensure => directory
      }
      if $key {
        file { "$home/.ssh":
            ensure => directory;
        }
        ssh_authorized_key { "$username":
          user    => $username,
          require => File["$home/.ssh"],
          key     => $key,
          type    => $keytype,
          ensure  => present;
        }
      }
    }

If this is a dependency issue, what's the best way to specify dependencies? Or am I doing something else wrong? General feedback would also be appreciated.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Puppet is probably not even trying to create the user, because you are making a virtual user::account resource (where you specify the "@"), but are only trying to realize a user resource (there are no virtual user resources).

Further, the filter group == developer would not match anything as there is no group attribute on either user, or user::account.

Try substituting User <| group == developer |> with Users::Account <| gid == developer |> and see if that helps.

share|improve this answer
    
That was spot on, thanks very much. Silly mistakes are the easiest to fix :) –  michaeltwofish Apr 20 '12 at 6:56

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.