diff --git a/apps/assets/forms.py b/apps/assets/forms.py index d8cd0b352..a7ba67364 100644 --- a/apps/assets/forms.py +++ b/apps/assets/forms.py @@ -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: diff --git a/apps/assets/tasks.py b/apps/assets/tasks.py index ca0a32e4e..4fc5b023b 100644 --- a/apps/assets/tasks.py +++ b/apps/assets/tasks.py @@ -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