已经试过在ubuntu上安装 puppet libshadow-ruby1.8
class users {
package { "libshadow-ruby1.8":
ensure => latest,
require => Exec['apt-get update']
}
user { "ubuntu":
ensure => present,
uid => '1001',
gid => 'admin',
shell => '/bin/bash',
password => sha1('ubuntu'),
managehome => true,
require => Package['libshadow-ruby1.8']
}
}
include users
这么写用户名是创建了, 但是密码还是没有
ps: 其实我是在用vagrant, vagrant是默认用户名想换成ubuntu
你说的“密码还是没有”是指你输入密码”ubuntu”时验证不通过吗?还是说shadow文件里根本没有ubuntu这条记录?
我猜是第一种(验证不通过),shadow文件中的密码好像不是sha1()生成的,我不知道你从哪看到的这个方法。
我想到的解决方案有:
在puppet class中使用shadow文件复制出来的密码
先在终端下用useradd, passswd创建用户,并设置密码为ubuntu,如图:
再去shadow文件中把加密后的密码复制出来,用这样的puppet代码创建用户:
user { "ubuntu":
ensure => present,
uid => '1001',
gid => 'admin',
shell => '/bin/bash',
password => '$6$mEUouB2K$zCgsWNuI0KhUvHbTcv6bV1UV2gx/VFB390zVOZ37lukr2PI7b4RKNkvpHaMRoG4zCqLvP0dN4p6uIi0xEZeRJ0',
managehome => true,
require => Package['libshadow-ruby1.8']
}
写个bash脚本,使用expect和passwd命令为新建的用户设置密码
由于passwd命令直接从stdin接收密码,不能通过passwd ubuntu ubuntu这样的命令行参数来设置密码,所以,变通的办法是自己写个bash shell(假设叫set_passwd.sh),这个shell脚本从命令行接收明文密码,再用expect传送给passwd命令
这样,你的puppet脚本如下:
user { "ubuntu":
ensure => present,
uid => '1001',
gid => 'admin',
shell => '/bin/bash',
managehome => true,
require => Package['libshadow-ruby1.8'],
notify => Exec['change_pass']
}
exec {'change_pass':
command => '/bin/sh /root/set_passwd.sh ubuntu[用户名] ubuntu[密码]',
require => File['/root/set_passwd.sh']
}
正文完