From 6c9ebd76d1d5dc6e9124c7d0b94e92905c519b65 Mon Sep 17 00:00:00 2001 From: Nilashish Chakraborty Date: Wed, 17 Jun 2020 08:39:43 +0530 Subject: [PATCH] Feature privilege status should only be checked if we need to escalate priv (https://github.com/ansible-collections/cisco.nxos/pull/61) (#69766) Check feature privilege status only if priv escalation is required Reviewed-by: https://github.com/apps/ansible-zuul Signed-off-by: NilashishC --- changelogs/fragments/fix_nxos_terminal_plugin_order.yaml | 3 +++ lib/ansible/plugins/terminal/nxos.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/fix_nxos_terminal_plugin_order.yaml diff --git a/changelogs/fragments/fix_nxos_terminal_plugin_order.yaml b/changelogs/fragments/fix_nxos_terminal_plugin_order.yaml new file mode 100644 index 00000000000..42d8ca8704e --- /dev/null +++ b/changelogs/fragments/fix_nxos_terminal_plugin_order.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Update terminal plugin to check feature privilege only when escalation is needed (https://github.com/ansible-collections/cisco.nxos/pull/61). diff --git a/lib/ansible/plugins/terminal/nxos.py b/lib/ansible/plugins/terminal/nxos.py index dbeab1f3ffc..e09bf08f7ef 100644 --- a/lib/ansible/plugins/terminal/nxos.py +++ b/lib/ansible/plugins/terminal/nxos.py @@ -57,8 +57,6 @@ class TerminalModule(TerminalBase): out = self._exec_cli_command('show privilege') out = to_text(out, errors='surrogate_then_replace').strip() - if 'Disabled' in out: - raise AnsibleConnectionFailure('Feature privilege is not enabled') # if already at privilege level 15 return if '15' in out: @@ -67,6 +65,9 @@ class TerminalModule(TerminalBase): if self.validate_user_role(): return + if 'Disabled' in out: + raise AnsibleConnectionFailure('Feature privilege is not enabled') + cmd = {u'command': u'enable'} if passwd: cmd[u'prompt'] = to_text(r"(?i)[\r\n]?Password: $", errors='surrogate_or_strict')