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.

My users.pp

class users::add
{
    define add_user ( $name, $comment, $home, $shell, $uid, $gid, $password)
    {


    # Create the user. This is where most of the magic happens.
    user { "$name":
    name => "$name",
    ensure => present,
    comment => "$comment",
    home => "$home",
    shell => "$shell",
    uid => "$uid",
    password => "$password",
    gid => "$gid"
    }


    file { "/home/$name/":
    ensure => directory,
    owner => $name,
    group => $gid,
    mode => 750,
    require => [User[$name]]
    }

    # And a place with the right permissions for the SSH related configs
    file { "/home/$name/.ssh":
    ensure => directory,
    owner => $name,
    group => $gid,
    mode => 700,
    require => File["/home/$name/"]
    }


    # Now make sure that the ssh key authorized files is around

    file { "/home/$name/.ssh/authorized_keys":
    ensure => present,
    owner => $name,
    group => $gid,
    mode => 600,
    require => file["/home/$name/.ssh"]
    }

  }

}

My site.pp

   import "classes/*.pp"
    node default{
    include users::add
    add_user{"saga":name => "saga",comment => "Arun Sag",gid => "100",home => "/home/saga",password => '$1$passwordhash/',shell => "/bin/bash",uid => "70960",
    }
    }

As you can see, i have created a defined type and wrapped it inside a users:add class. I tried to call from site.pp, but when i tried to test this

sudo puppet master --compile=darkguard-dr.eglbp.corp.company.com --debug --verbose

debug: Using cached node for darkguard-dr.eglbp.corp.company.com                                                               
debug: importing '/etc/puppet/manifests/classes/users.pp' in environment production                                          
warning: Deprecation notice:  Resource references should now be capitalized on line 49 in file /etc/puppet/manifests/classes/
users.pp                                                                                                                     
err: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type add_user at /etc/puppet/manifests/s
ite.pp:5 on node darkguard-dr.eglbp.corp.company.com                                                                           
Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type add_user at

/etc/puppet/manifests/site.p p:5 on node darkguard-dr.eglbp.corp.company.com

i get above error message. I am also planning to generate yaml using a ENC script. What must be the yaml format?

share|improve this question

1 Answer 1

Two things regarding your puppet code.

The define should be in it's own file (named add_user.pp, and located in the <modulename>/manifests/ folder) , rather than in the class file.

Set the define up (change $name to $username, as $name is a reserved variable), and then add the same set of parameters as the define uses to the class. (which in your example would be $modulepath/users/manifests/add.pp to make it work with the autoloader)

If you change the class as follows:

class users::add( $u_name, $u_comment, $u_home, $u_shell, $u_uid, $u_gid, $u_password)
{
  users::add_user{ $u_name:
    $username => $u_name, 
    $comment  => $u_comment, 
    $home     => $u_home, 
    $shell    => $u_shell, 
    $uid      => $u_uid, 
    $gid      => $u_gid, 
    $password => $u_password,
  }
}

And change the site.pp to:

 import "classes/*.pp"
    node default{
      class { 'add_user': 
        username => "saga",
        comment => "Arun Sag",
        gid => "100",
        home => "/home/saga",
        password => '$1$passwordhash/',
        shell => "/bin/bash",
        uid => "70960",
      }
    }

For the yaml, something like this will do it, please refer to the documentation for more details:

---
classes:
  users::add:

parameters:
  name: some_name
  comment: some_comment
  home: home_value
  shell: /bin/sh
  uid: 3990
  gid: 3990
  password: superstrongpassword

environment:
  production
share|improve this answer
    
Quick question: The yaml file has parameters to create one username and password, is it possible to create multiple user accounts?? –  zer0c00l Jul 18 '12 at 13:56
    
Yes, but since you can't use a define directly from an ENC, you'd have to rework things a little to make use of either create_resources or a hash of the users. Unfortunately, I am not very familiar with that function. –  Lee Lowder Jul 18 '12 at 14:16
    
While running 'sudo puppet agent --test --debug' "err: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not parse for environment production: Syntax e rror at 'username'; expected '}' at /etc/puppet/manifests/classes ./users.pp:4 on node battleoffer-dr.eglbp.corp.company.com warning: Not using cache on failed catalog err: Could not retrieve catalog; skipping run" The users.pp has the class definition. I have created add.pp at the module in /usr/share/puppet/modules/ –  zer0c00l Jul 18 '12 at 14:34
    
I would even recommend splitting it out into its own module, instead of just a .pp file to be included. –  lsd Jul 18 '12 at 19:35

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.