Skip to content
3 changes: 3 additions & 0 deletions changelogs/fragments/758_fix_nxos_user.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- nxos_user - fix Salt (6->8 as supported by Cisco NX-OS) chars
2 changes: 1 addition & 1 deletion plugins/modules/nxos_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def main():

# check if provided hashed password is infact a hash
if module.params["hashed_password"] is not None:
if not re.match(r"^\$5\$......\$.*$", module.params["hashed_password"]):
if not re.match(r"^\$5\$........\$.*$", module.params["hashed_password"]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vvas1lev Thank you for the PR. But I'm unsure if what you're proposing in this is valid for all NX-OS versions. For example:

nexus9300# show version | in NXOS:
  NXOS: version 10.3(1) [Feature Release]
nexus9300# show running-config | in username
username admin password 5 $5$EJHAFP$eDk9h6gmq9A4.krEm//hHe.uDDlNXTLZfUaMQVWyWZ8 
 role network-admin
username cisco password 5 $5$JHNODB$9nuq8XjLNpYOrCJ9D6CdBbS31THfsLWp6Yq3LzfUZ78 
 role network-admin

The hash seems to be 6 characters here. IMO, the ideal solution should be something more generic like \$5\$.+\$.*$, which accounts for both the cases.

module.fail_json(msg="Provided hash is not valid")

if commands:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/modules/network/nxos/test_nxos_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ def test_nxos_hashed_password(self):
set_module_args(
dict(
name="ansible",
hashed_password="$5$JFHICC$u.zXRUgprAkkYLiEns8VrhsNEIOj7FzVrn67tuJdtKB",
hashed_password="$5$VVJFHICC$u.zXRUgprAkkYLiEns8VrhsNEIOj7FzVrn67tuJdtKB",
),
)
self.execute_module(
changed=True,
commands=[
"username ansible",
"username ansible password 5 $5$JFHICC$u.zXRUgprAkkYLiEns8VrhsNEIOj7FzVrn67tuJdtKB",
"username ansible password 5 $5$VVJFHICC$u.zXRUgprAkkYLiEns8VrhsNEIOj7FzVrn67tuJdtKB",
],
)