From 8de46f5cf78abc219d71269537290e5b13c75d7a Mon Sep 17 00:00:00 2001 From: linnil1 Date: Tue, 4 Dec 2018 23:49:13 +0800 Subject: [PATCH] [Junos] Fix bug of setting user password (#44660) * Add encrypted_password for junos * Add readme for Junos user encrypted_password * encrypted_password added in 2.8 --- .../modules/network/junos/junos_user.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/ansible/modules/network/junos/junos_user.py b/lib/ansible/modules/network/junos/junos_user.py index cdca5dc5dc2..3a17bfe4a3e 100644 --- a/lib/ansible/modules/network/junos/junos_user.py +++ b/lib/ansible/modules/network/junos/junos_user.py @@ -57,6 +57,11 @@ options: - The C(sshkey) argument defines the public SSH key to be configured for the user account on the remote system. This argument must be a valid SSH key + encrypted_password: + description: + - The C(encrypted_password) argument set already hashed password + for the user account on the remote system. + version_added: "2.8" purge: description: - The C(purge) argument instructs the module to consider the @@ -109,6 +114,13 @@ EXAMPLES = """ - name: ansible purge: yes +- name: set user password + junos_user: + name: ansible + role: super-user + encrypted_password: "{{ 'my-password' | password_hash('sha512') }}" + state: present + - name: Create list of users junos_user: aggregate: @@ -218,6 +230,11 @@ def map_obj_to_ele(module, want): ssh_rsa = SubElement(auth, 'ssh-ed25519') key = SubElement(ssh_rsa, 'name').text = item['sshkey'] + if item.get('encrypted_password'): + if 'auth' not in locals(): + auth = SubElement(user, 'authentication') + SubElement(auth, 'encrypted-password').text = item['encrypted_password'] + return element @@ -267,6 +284,7 @@ def map_params_to_obj(module): item.update({ 'full_name': get_value('full_name'), 'role': get_value('role'), + 'encrypted_password': get_value('encrypted_password'), 'sshkey': get_value('sshkey'), 'state': get_value('state'), 'active': get_value('active') @@ -290,6 +308,7 @@ def main(): name=dict(), full_name=dict(), role=dict(choices=ROLES), + encrypted_password=dict(), sshkey=dict(), state=dict(choices=['present', 'absent'], default='present'), active=dict(type='bool', default=True)