[Bugfix] 修改创建系统用户的bug

pull/1043/head
ibuler 2018-02-02 19:04:09 +08:00
parent 45f6a62989
commit 114289edaf
2 changed files with 12 additions and 9 deletions

View File

@ -308,7 +308,7 @@ class SystemUserForm(PasswordAndKeyAuthForm):
auto_generate_key = self.cleaned_data.get('auto_generate_key', False)
private_key, public_key = super().gen_keys()
if not self.instance and auto_generate_key:
if auto_generate_key:
logger.info('Auto generate key and set system user auth')
system_user.auto_gen_auth()
else:

View File

@ -314,8 +314,10 @@ def get_push_system_user_tasks(system_user):
if system_user.username == "root":
return []
tasks = [
{
tasks = []
if system_user.password:
tasks.append({
'name': 'Add user {}'.format(system_user.username),
'action': {
'module': 'user',
@ -324,8 +326,9 @@ def get_push_system_user_tasks(system_user):
encrypt_password(system_user.password, salt="K3mIlKK"),
),
}
},
{
})
if system_user.public_key:
tasks.append({
'name': 'Set {} authorized key'.format(system_user.username),
'action': {
'module': 'authorized_key',
@ -333,8 +336,9 @@ def get_push_system_user_tasks(system_user):
system_user.username, system_user.public_key
)
}
},
{
})
if system_user.sudo:
tasks.append({
'name': 'Set {} sudo setting'.format(system_user.username),
'action': {
'module': 'lineinfile',
@ -345,8 +349,7 @@ def get_push_system_user_tasks(system_user):
system_user.sudo,
)
}
}
]
})
return tasks