[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
This commit is contained in:
linnil1 2018-12-04 23:49:13 +08:00 committed by John R Barker
parent 5cb39d0d57
commit 8de46f5cf7

View file

@ -57,6 +57,11 @@ options:
- The C(sshkey) argument defines the public SSH key to be configured - The C(sshkey) argument defines the public SSH key to be configured
for the user account on the remote system. This argument must for the user account on the remote system. This argument must
be a valid SSH key 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: purge:
description: description:
- The C(purge) argument instructs the module to consider the - The C(purge) argument instructs the module to consider the
@ -109,6 +114,13 @@ EXAMPLES = """
- name: ansible - name: ansible
purge: yes 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 - name: Create list of users
junos_user: junos_user:
aggregate: aggregate:
@ -218,6 +230,11 @@ def map_obj_to_ele(module, want):
ssh_rsa = SubElement(auth, 'ssh-ed25519') ssh_rsa = SubElement(auth, 'ssh-ed25519')
key = SubElement(ssh_rsa, 'name').text = item['sshkey'] 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 return element
@ -267,6 +284,7 @@ def map_params_to_obj(module):
item.update({ item.update({
'full_name': get_value('full_name'), 'full_name': get_value('full_name'),
'role': get_value('role'), 'role': get_value('role'),
'encrypted_password': get_value('encrypted_password'),
'sshkey': get_value('sshkey'), 'sshkey': get_value('sshkey'),
'state': get_value('state'), 'state': get_value('state'),
'active': get_value('active') 'active': get_value('active')
@ -290,6 +308,7 @@ def main():
name=dict(), name=dict(),
full_name=dict(), full_name=dict(),
role=dict(choices=ROLES), role=dict(choices=ROLES),
encrypted_password=dict(),
sshkey=dict(), sshkey=dict(),
state=dict(choices=['present', 'absent'], default='present'), state=dict(choices=['present', 'absent'], default='present'),
active=dict(type='bool', default=True) active=dict(type='bool', default=True)