sebastien/cuisine — Issue #50: user_check: index out of range
Author: josephmc5
Created: 2012-02-13 20:19:03+00:00
State: open

i have a list of over 5 servers and on one of them i get this error:

[server.url.com] sudo: cat /etc/shadow | egrep '^username:' | awk -F':' '{print $2}'
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/fabric/main.py", line 684, in main
*args, **kwargs
File "/Library/Python/2.6/site-packages/fabric/tasks.py", line 235, in execute
task.run(*args, **new_kwargs)
File "/Library/Python/2.6/site-packages/fabric/tasks.py", line 105, in run
return self.wrapped(*args, **kwargs)
File "/Users/jmcwilliams/code/fab_manage/fabfile.py", line 148, in add_user
if not user_check(username):
File "/Library/Python/2.6/site-packages/cuisine.py", line 572, in user_check
results = dict(name=d[0], uid=d[2], gid=d[3], home=d[5], shell=d[6])
IndexError: list index out of range

Here is my function

def add_user(username,password):
if not user_check(username):
mode_sudo()
redhat_release = '/etc/redhat-release'
if file_exists(redhat_release):
group = 'wheel'
else:
group = 'sudo'
print('#' *60)
print("Creating user %s" % username)
print('#' *60)
user_create(username, shell='/bin/bash')

print('#' *60)
print("Adding %s to sudo group" % username)
print('#' *60)
group_user_add(group, username)

print('#' *60)
print("Setting password to " + password)
print('#' *60)
sudo('echo "{username}:{password}" | chpasswd'.format(username=username, password=password))

try:
file_local_read('user_keys/%s/ssh_key.pub' % username)
key_file = '/home/%s/.ssh/authorized_keys' % username
user_key = file_local_read('user_keys/%s/ssh_key.pub' % username)
if not fabric.contrib.files.contains(key_file, user_key):
dir_ensure('/home/%s/.ssh' % username)
fabric.contrib.files.append(key_file, user_key, use_sudo=True)
file_ensure(key_file, mode=600, owner='%s' % username)
except:
print("User does not have a public key in user_keys")
else:
print("User already exists.")