已经试过在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
When you say "there is still no password", do you mean that the verification failed when you entered the password "ubuntu"? Or is there no ubuntu record in the shadow file at all?
I guess it’s the first one (verification failed). The password in the shadow file doesn’t seem to be generated by sha1(). I don’t know where you saw this method.
The solutions I thought of are:
Use the password copied from the shadow file in the puppet classFirst create a user in the terminal using useradd, passswd, and set the password to ubuntu, as shown in the picture:
Write a bash script and use the expect and passwd commands to set the password for the new userThen go to the shadow file and copy the encrypted password, and use this puppet code to create a user:
Since the passwd command receives the password directly from stdin, the password cannot be set through command line parameters such as passwd ubuntu ubuntu, so the workaround is Write a bash shell yourself (assuming it's called set_passwd.sh). This shell script receives the plaintext password from the command line, and then uses expect to send it to the passwd command
In this way, your puppet script is as follows: