Puppet Test 用户管理

测试环境架构图

test-puppet_0507

服务端配置目录树

|-- fileserver.conf
|-- manifests
|   |-- nodes.pp
|   `-- site.pp
|-- modules        #定义模块
|   `-- users
|       |-- file
|       |-- manifests
|       |   |-- adduser.pp
|       |   |-- deluser.pp
|       |   |-- init.pp
|       |   |-- na.pp
|       |   `-- sa.pp
|       `-- templates
|           |-- caojin_authorized_keys.erb
|           `-- jiaxin_authorized_keys.erb
|-- puppet.conf    #主配置配置文件

用户管理模块

user mofules 目录树

users
|-- file
|-- manifests
    |   |-- adduser.pp #添加用户类
    |   |-- deluser.pp #删除用户
    |   |-- init.pp
    |   |-- na.pp
    |   `-- sa.pp
    `-- templates
        |-- caojin_authorized_keys.erb #用户key
        `-- jiaxin_authorized_keys.erb #用户key

adduser.pp 文件

class linux::adduser {
   define add_user ($username=, $useruid=, $userhome=, $usershell='/bin/bash', $groups)
   {
       user
       {   $username:
           uid   => $useruid,
           shell => $usershell,
           groups => $groups,
           home  => "/home/$userhome",
       }
       file 
       {   "/home/$userhome":
           owner   => $useruid,
           group   => $useruid,
           mode    => 700,
           ensure  => directory;
       }
       file
       {   "/home/$userhome/.ssh":
           owner   => $useruid,
           group   => $useruid,
           mode    => 700,
           ensure  => directory,
           require => File["/home/$userhome"];
       }
       file
       {   "/home/$userhome/.ssh/authorized_keys":
           owner   => $useruid,
           group   => $useruid,
           mode    => 600,
           ensure  => present, 
           content => template("users/${userhome}_authorized_keys.erb"),
           require => File["/home/$userhome/.ssh"]; 
       }
   }
}

deluser.pp

deluser.pp
class linux::deluser
{
       user
       {
           "caojin":
           ensure  => absent,
       }
}

sa.pp

import "adduser.pp"

class linux::adduser::sa inherits linux::adduser
{
    add_user
    {
        "jiaxin":
        useruid     => 2000,
        username    => jiaxin,
        userhome    => "jiaxin",
        groups      => $operatingsystem ? {
        Ubuntu    => ["admin"],
        CentOS    => ["wheel"],
        RedHat    => ["wheel"],
        default    => ["wheel"],
    },
    }
}
除非特别注明,本页内容采用以下授权方式: Creative Commons Attribution-ShareAlike 3.0 License