我试图用puppet管理Unix用户. Puppet提供了足够的工具来创建帐户并提供authorized_keys文件,但是没有设置用户密码,它告诉用户.
我所做的是一个python脚本,它生成一个随机密码并通过电子邮件发送给用户.问题是,用python启动passwd Unix命令是不可能的,然后我用命令编写了一个bash脚本:
echo -ne "$password\n$password\n" | passwd $user
passwd -e $user
手动启动,脚本运行正常,创建的用户通过电子邮件发送密码.但是当puppet启动它时,只会执行python脚本,就好像os.system(‘/ bin / bash my_bash_script’)被忽略一样.没有显示错误.并且用户获取其密码,但未启动passwd命令.
傀儡是否有任何限制阻止执行我所描述的内容?或者,我如何通过电子邮件更改用户帐户,过期和发送密码?
我可以提供更多信息,但是现在,我不知道哪些是准确的.
非常感谢!
编辑:这是一个具有相同症状的基本代码:
python:setuserpassword.py
#!/usr/bin/python
import os
import sys
user = sys.argv[1]
mail = sys.argv[2]
os.system('/bin/bash /root/tools/setuserpassword.sh '+user+' '+mail)
bash:setuserpassword.sh
#!/bin/bash
# Password setup for the account
password=`pwgen -N1 --secure 10`
echo -ne "$password\n$password\n" | passwd $USER > /dev/null 2>&1
[[ $? -ne 0 ]] && exit 2
# Setup the expirancy label to make sure user
# change its password upon fist success login
chage -d0 $USER
# Email sending to inform user of his new password
echo -ne "Hello,$USER;\n
The password is:\n
$password\n" | mail -s "$USER account created" $MAIL
这是模块(这方面没问题)
define add_user ( $email,$uid,$gid ) {
$username = $title
user { $username:
comment => "$email",home => "/home/$username",shell => "/bin/bash",uid => $uid,gid => $gid,}
exec { "/root/tools/setuserpassword.py $username $email":
path => "/bin:/usr/bin:/usr/sbin/sbin",refreshonly => true,subscribe => user[$username],onlyif => "cat /etc/shadow | grep $username | grep '!'",require => Package['pwgen'],}