How about this? Check if uid == 0
:
[kbrandt@kbrandt-admin: ~] python -c 'import os; print os.getuid()'
196677
[kbrandt@kbrandt-admin: ~] sudo python -c 'import os; print os.getuid()'
0
No need to use a bash script, just use the next function I'm using for some other stuff to generate the shadow encrypted password:
def shadow(self,password):
SomeZolt="$6$"+''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(9))+"$"
return crypt.crypt(password, SomeZolt)
After which write additional functionality to your python script which will open the /etc/shadow file and write the encrypted password you get by using this function for this user thus making a line like:
some_user:!!:15579:0:99999:7:::
make look like:
some_user:$1$JShdquwdjsd38hSJhdqwdkwd:15579:0:99999:7:::
Thus some_user will have the assigned password.
Additionaly you can set the user directly in the puppet statement by changing it to:
user { $username:
comment => "$email",
home => "/home/$username",
shell => "/bin/bash",
uid => $uid,
gid => $gid,
password => "SomeAlreadyEncryptedPassword",
}
You can use by the way the function specified to get the encrypted password and then insert it to the statement.
Best Answer