本文系统Centos6.0

master:master.lansgg.com 192.168.182.143

client1 :client1.lansgg.com 192.168.182.142

client2: client2.lansgg.com 192.168.182.149

相关安装请看:http://lansgg.blog.51cto.com/5675165/1299604

很简单的:

案例1:在client1、client2上创建一个用户zhangsan

首先查看下master上的注册信息是否正确:

153421567.jpg

注册证书OK;

master端:

[root@master ~]# vim /etc/puppet/manifests/site.pp
import "node1.pp"

编写site.pp文件中包含的pp

[root@master ~]# vim /etc/puppet/manifests/node1.pp
user    {"zhangsan":               
        ensure => present,
        uid => 1001,
        gid => 1001,
#       home => "/home/zhangsan",      #此为可以创建非默认的家目录
        comment => "test's user",    #此为描述信息
        managehome => true,          #自动创建家目录
        password => '$1$uvqOM1$4dTiuTlz/iWzj1sJEKaU9.',  #密码
        groups => test,     同时将zhangsan加入test组
        shell => "/bin/bash"; 
        }
group {"zhangsan":
        gid => 1001,
        ensure => "present",
        }

PS:上面的password属性的字符串:

[root@master manifests]# grub-md5-crypt
Password:
Retype password:
$1$uvqOM1$4dTiuTlz/iWzj1sJEKaU9.

接下来在client2进行测试:

181251428.jpg

可以看到测试ok;你也可以通过ssh测试的密码正确性;

案例2、我们将zhangsan用户删除;

master端:

[root@master ~]# vim /etc/puppet/manifests/site.pp
import "node.pp"
[root@master ~]# vim /etc/puppet/manifests/node.pp
user {"zhangsan":
        ensure => absent,
        }

我们在client端进行测试:

181606904.jpg

案例3、我们在不同的机器上创建不同的用户,client1上创建test1,client2上创建test2;

[root@master ~]# vim /etc/puppet/manifests/site.pp
import "node1.pp"
[root@master ~]# vim /etc/puppet/manifests/node1.pp
node 'client1.lansgg.com' {
user    {"test1":
        ensure => present,
        uid => 999,
        gid => 999,
        managehome => true,
        password => '$1$uvqOM1$4dTiuTlz/iWzj1sJEKaU9.',
        shell => "/bin/bash";
        }
group {"test1":
        gid => 999,
        ensure => "present",
        }
}
node 'client2.lansgg.com' {
user    {"test2":
        ensure => present,
        uid => 999,
        gid => 999,
        managehome => true,
        password => '$1$.jwPM1$xwWcMBrxirMxRjrxbRIRM.',
        shell => "/bin/bash";
        }
group {"test2":
        gid => 999,
        ensure => "present",
        }
}

分别在client1、client2执行:

puppetd --test --server master.lansgg.com --verbose

输出内容不贴图了;

下面直接验证在机器的用户test1和test2;

184805577.jpg

可以看到用户是OK的;