Repository: ansible/ansible
Pull request: [Junos] Fix bug of setting user password
##### SUMMARY
<!--- Describe the change, including rationale and design decisions -->
Add user encrypted_password option.

<!--- If you are fixing an existing issue, please include "Fixes #nnn" in your
commit message and your description; but you should still explain what
the change does.-->
Fixes #32683

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Feature Pull Request
 - Bugfix Pull Request

##### COMPONENT NAME
<!--- Name of the module, plugin, task or feature -->
junos_user

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.7.0.dev0
  config file = /project/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.15 (default, Jul 31 2018, 23:03:52) [GCC 6.3.0 20170516]
```


##### ADDITIONAL INFORMATION
<!--- Include additional information to help people understand the change here.
For bugs that don't have a linked bug report, a step-by-step reproduction
of the problem is helpful. -->

<!--- Paste verbatim command output below, e.g. before and after your change -->
```

```


Problem statement:
junos_user missing 'configured_password' parameter
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->
The junos_user module is missing the 'configured_password' parameter.  Without this parameter, passwords cannot be configured for the users that are added.

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
junos_user

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.0.0
  config file = /Users/scarter/.ansible.cfg
  configured module search path = [u'/Users/scarter/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
HOST_KEY_CHECKING(/Users/scarter/.ansible.cfg) = False

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).

-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Centos in a docker container

##### SUMMARY
<!--- Explain the problem briefly -->
The junos_user module is missing the 'configured_password' parameter.  Without this parameter, passwords cannot be configured for the users that are added.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
    - name: Add user
      net_user:
        name: user
        configured_password: password
        state: present
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
I expected it to add a user with the specified password as it does on the other platforms.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
See error below

<!--- Paste verbatim command output between quotes below -->
```
fatal: [j2300-1.ismc.io]: FAILED! => {"ansible_facts": {"network_os": "junos"}, "changed": false, "failed": true, "msg": "Unsupported parameters for (junos_user) module: configured_password Supported parameters include: active,aggregate,full_name,host,name,password,port,provider,purge,role,ssh_keyfile,sshkey,state,timeout,transport,username"}
```

Hints from issue discussion:
cc @Qalthos @ganeshrn @privateip
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Commit message: Add readme for Junos user encrypted_password

Patch to review:
diff --git a/lib/ansible/modules/network/junos/junos_user.py b/lib/ansible/modules/network/junos/junos_user.py
index cdca5dc5dc2112..d481b29bb510f3 100644
--- a/lib/ansible/modules/network/junos/junos_user.py
+++ b/lib/ansible/modules/network/junos/junos_user.py
@@ -57,6 +57,11 @@
       - 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.7"
   purge:
     description:
       - The C(purge) argument instructs the module to consider the
@@ -109,6 +114,13 @@
     - 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)


Code review comments:
diff_hunk: @@ -57,6 +57,11 @@
       - 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.7"
path: lib/ansible/modules/network/junos/junos_user.py
text: @user1:
Please change this to `version_added: "2,8"`