From 001bbaad96b44401e95c25ca78dc0256a98d8d34 Mon Sep 17 00:00:00 2001 From: Taseer Ahmed Date: Thu, 16 Aug 2018 16:18:17 +0500 Subject: [PATCH] Allow user passwords to be updated 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 --- library/odl_usermod.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/library/odl_usermod.py b/library/odl_usermod.py index 8ce0956..7710122 100644 --- a/library/odl_usermod.py +++ b/library/odl_usermod.py @@ -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") -- 2.36.6