我的用户.pp

我的用户.pp

我的用户.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"]
    }

  }

}

我的网站.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",
    }
    }

如您所见,我创建了一个定义类型并将其包装在 users:add 类中。我尝试从 site.pp 调用,但当我尝试测试此

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

节点 darkguard-dr.eglbp.corp.company.com 上的 /etc/puppet/manifests/site.p p:5

我收到上述错误消息。我还计划使用 ENC 脚本生成 yaml。yaml 格式应该是什么?

答案1

关于你的傀儡代码有两件事。

定义应该在它自己的文件中(名为 add_user.pp,位于<modulename>/manifests/文件夹中),而不是在类文件中。

设置定义(将 $name 更改为 $username,因为 $name 是保留变量),然后向类添加与定义使用的相同的一组参数。(在您的示例中,这将使其$modulepath/users/manifests/add.pp与自动加载器一起工作)

如果你按如下方式更改类:

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,
  }
}

并将 site.pp 更改为:

 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",
      }
    }

对于 yaml,类似这样的操作即可,请参阅文档更多细节:

---
classes:
  users::add:

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

environment:
  production

相关内容