Allow user passwords to be updated 11/75311/1
authorTaseer Ahmed <taseer94@gmail.com>
Thu, 16 Aug 2018 11:18:17 +0000 (16:18 +0500)
committerTaseer Ahmed <taseer94@gmail.com>
Mon, 20 Aug 2018 03:40:33 +0000 (08:40 +0500)
This patch adds a new state that will update the password of
an existing user. This state requires the username for which
the password needs to be changed.

JIRA: INTPAK-16

Change-Id: I01983df6bdb61f480f819738b9467a10a6ef1013
Signed-off-by: Taseer Ahmed <taseer94@gmail.com>
library/odl_usermod.py

index 8ce0956ad4cab56711d2cf584d6f4c3372a271d5..77101226545796582860551d47eba8a743781b59 100644 (file)
@@ -42,6 +42,12 @@ EXAMPLES = \
     - name: list odl users
       odl_usermod:
         state: list
+
+    - name: change user password
+      odl_usermod:
+        username: admin
+        password: admin
+        state: update
 '''
 
 
@@ -111,6 +117,15 @@ def main():
         if users[0] == 'User names:':
             users.pop(0)
         module.exit_json(changed=False, msg=users)
+    elif state == 'update':
+        if not username or not password:
+            module.exit_json(changed=False, failed=True,
+                             msg="Username or password not provided")
+        cmd = build_cmd(module, "--cu", username, '-p', password)
+        (rc, out, err) = module.run_command(cmd)
+        if rc is not None and rc != 0:
+            return module.fail_json(msg=err)
+        module.exit_json(changed=True, msg="Password changed")
     else:
         module.exit_json(changed=False, msg="No state specified")