diff --git a/lib/ansible/modules/network/iosxr/iosxr_user.py b/lib/ansible/modules/network/iosxr/iosxr_user.py index 30205f4df5b..9e4b8356e8c 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_user.py +++ b/lib/ansible/modules/network/iosxr/iosxr_user.py @@ -83,6 +83,14 @@ options: `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" state: description: - Configures the state of the username definition @@ -123,6 +131,12 @@ EXAMPLES = """ 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 @@ -478,7 +492,8 @@ class CliConfiguration(ConfigBase): 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) @@ -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(), diff --git a/test/units/modules/network/iosxr/test_iosxr_user.py b/test/units/modules/network/iosxr/test_iosxr_user.py index 3c07f89680f..755520fffdc 100644 --- a/test/units/modules/network/iosxr/test_iosxr_user.py +++ b/test/units/modules/network/iosxr/test_iosxr_user.py @@ -87,3 +87,8 @@ class TestIosxrUserModule(TestIosxrModule): 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'])