Fix nxos_user roles bug (#65962)
This commit is contained in:
parent
52f3ce8a80
commit
c2fed8603c
3 changed files with 25 additions and 13 deletions
|
@ -174,12 +174,30 @@ def map_obj_to_commands(updates, module):
|
||||||
def remove(x):
|
def remove(x):
|
||||||
return commands.append('no username %s %s' % (want['name'], x))
|
return commands.append('no username %s %s' % (want['name'], x))
|
||||||
|
|
||||||
|
def configure_roles():
|
||||||
|
if want['roles']:
|
||||||
|
if have:
|
||||||
|
for item in set(have['roles']).difference(want['roles']):
|
||||||
|
remove('role %s' % item)
|
||||||
|
|
||||||
|
for item in set(want['roles']).difference(have['roles']):
|
||||||
|
add('role %s' % item)
|
||||||
|
else:
|
||||||
|
for item in want['roles']:
|
||||||
|
add('role %s' % item)
|
||||||
|
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
if want['state'] == 'absent':
|
if want['state'] == 'absent':
|
||||||
commands.append('no username %s' % want['name'])
|
commands.append('no username %s' % want['name'])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
roles_configured = False
|
||||||
if want['state'] == 'present' and not have:
|
if want['state'] == 'present' and not have:
|
||||||
commands.append('username %s' % want['name'])
|
roles_configured = configure_roles()
|
||||||
|
if not roles_configured:
|
||||||
|
commands.append('username %s' % want['name'])
|
||||||
|
|
||||||
if needs_update('configured_password'):
|
if needs_update('configured_password'):
|
||||||
if update_password == 'always' or not have:
|
if update_password == 'always' or not have:
|
||||||
|
@ -188,16 +206,8 @@ def map_obj_to_commands(updates, module):
|
||||||
if needs_update('sshkey'):
|
if needs_update('sshkey'):
|
||||||
add('sshkey %s' % want['sshkey'])
|
add('sshkey %s' % want['sshkey'])
|
||||||
|
|
||||||
if want['roles']:
|
if not roles_configured:
|
||||||
if have:
|
configure_roles()
|
||||||
for item in set(have['roles']).difference(want['roles']):
|
|
||||||
remove('role %s' % item)
|
|
||||||
|
|
||||||
for item in set(want['roles']).difference(have['roles']):
|
|
||||||
add('role %s' % item)
|
|
||||||
else:
|
|
||||||
for item in want['roles']:
|
|
||||||
add('role %s' % item)
|
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,13 @@
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
- debug: msg="{{result}}"
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- 'result.changed == true'
|
- 'result.changed == true'
|
||||||
- '"username" in result.commands[0]'
|
- '"username" in result.commands[0]'
|
||||||
- '"role network-operator" in result.commands[1]'
|
- '"role network-operator" in result.commands[0]'
|
||||||
|
|
||||||
- name: Collection of users
|
- name: Collection of users
|
||||||
nxos_user:
|
nxos_user:
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
that:
|
that:
|
||||||
- 'result.changed == true'
|
- 'result.changed == true'
|
||||||
- '"username" in result.commands[0]'
|
- '"username" in result.commands[0]'
|
||||||
- '"role network-operator" in result.commands[1]'
|
- '"role network-operator" in result.commands[0]'
|
||||||
|
|
||||||
- name: teardown
|
- name: teardown
|
||||||
net_user:
|
net_user:
|
||||||
|
|
Loading…
Reference in a new issue