Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to enter admin configuration mode in iosxr_user #51430

Merged
merged 3 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/ansible/modules/network/iosxr/iosxr_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@
`admin` user and the current defined set of users.
type: bool
default: false
admin:
description:
- Enters into administration configuration mode for making config
changes to the device.
- Applicable only when using network_cli transport
type: bool
default: false
version_added: "2.8"
Copy link
Contributor

Choose a reason for hiding this comment

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

@NilashishC can you give a related example under examples, so that user may get to know how to use the respective admin config mode.

state:
description:
- Configures the state of the username definition
Expand Down Expand Up @@ -123,6 +131,12 @@
name: ansible
configured_password: mypassword
state: present
- name: create a new user in admin configuration mode
iosxr_user:
name: ansible
configured_password: mypassword
admin: True
state: present
- name: remove all users except admin
iosxr_user:
purge: True
Expand Down Expand Up @@ -478,7 +492,8 @@ def map_obj_to_commands(self):
self._result['commands'] = []
if commands:
commit = not self._module.check_mode
diff = load_config(self._module, commands, commit=commit)
admin = self._module.params['admin']
diff = load_config(self._module, commands, commit=commit, admin=admin)
if diff:
self._result['diff'] = dict(prepared=diff)

Expand Down Expand Up @@ -638,6 +653,8 @@ def main():
configured_password=dict(no_log=True),
update_password=dict(default='always', choices=['on_create', 'always']),

admin=dict(type='bool', default=False),

public_key=dict(),
public_key_contents=dict(),

Expand Down
5 changes: 5 additions & 0 deletions test/units/modules/network/iosxr/test_iosxr_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ def test_iosxr_user_update_password_always(self):
set_module_args(dict(name='ansible', configured_password='test', update_password='always'))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['username ansible secret test'])

def test_iosxr_user_admin_mode(self):
set_module_args(dict(name='ansible-2', configured_password='test-2', admin=True))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['username ansible-2', 'username ansible-2 secret test-2'])