Skip to content

Commit

Permalink
eos_user: sends user secret first on user creation fixes #31680 (#32162)
Browse files Browse the repository at this point in the history
* fix command order

* add integration test

* test cleanup

* remove redudant commands

(cherry picked from commit 602a618)
  • Loading branch information
dathelen authored and abadger committed Oct 26, 2017
1 parent 541d5db commit 2340c7a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/ansible/modules/network/eos/eos_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,16 @@ def map_obj_to_commands(updates, module):
commands.append('no username %s' % want['name'])
continue

if needs_update('configured_password'):
if update_password == 'always' or not have:
add('secret %s' % want['configured_password'])

if needs_update('role'):
add('role %s' % want['role'])

if needs_update('privilege'):
add('privilege %s' % want['privilege'])

if needs_update('configured_password'):
if update_password == 'always' or not have:
add('secret %s' % want['configured_password'])

if needs_update('sshkey'):
add('sshkey %s' % want['sshkey'])

Expand Down
26 changes: 23 additions & 3 deletions test/integration/targets/eos_user/tests/cli/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
- no username ansibletest1
- no username ansibletest2
- no username ansibletest3
- no username ansibletest4
provider: "{{ cli }}"

- name: Create user
- name: Create user with role
eos_user:
name: ansibletest1
privilege: 15
Expand All @@ -22,9 +23,27 @@
that:
- 'result.changed == true'
- '"username" in result.commands[0]'
- '"role network-operator" in result.commands[0]'
- '"secret" in result.commands[0]'
- '"role network-operator" in result.commands[1]'
- '"privilege 15" in result.commands[2]'

- name: Create user with priv level and update_password
eos_user:
name: ansibletest4
privilege: 15
state: present
configured_password: test1
authorize: yes
update_password: on_create
provider: "{{ cli }}"
register: result

- assert:
that:
- 'result.changed == true'
- '"username" in result.commands[0]'
- '"secret" in result.commands[0]'
- '"privilege 15" in result.commands[1]'
- '"secret" in result.commands[2]'

- name: Collection of users
eos_user:
Expand Down Expand Up @@ -69,4 +88,5 @@
- no username ansibletest1
- no username ansibletest2
- no username ansibletest3
- no username ansibletest4
provider: "{{ cli }}"

0 comments on commit 2340c7a

Please sign in to comment.