diff --git a/lib/ansible/modules/network/nxos/nxos_hsrp.py b/lib/ansible/modules/network/nxos/nxos_hsrp.py index a108fbe56c..2135fe20ca 100644 --- a/lib/ansible/modules/network/nxos/nxos_hsrp.py +++ b/lib/ansible/modules/network/nxos/nxos_hsrp.py @@ -211,6 +211,8 @@ def get_hsrp_group(group, interface, module): try: body = run_commands(module, [command])[0] hsrp_table = body['TABLE_grp_detail']['ROW_grp_detail'] + if 'unknown enum:' in str(hsrp_table): + hsrp_table = get_hsrp_group_unknown_enum(module, command, hsrp_table) except (AttributeError, IndexError, TypeError, KeyError): return {} @@ -239,6 +241,19 @@ def get_hsrp_group(group, interface, module): return hsrp +def get_hsrp_group_unknown_enum(module, command, hsrp_table): + '''Some older NXOS images fail to set the attr values when using structured output and + instead set the values to . This fallback method is a workaround that + uses an unstructured (text) request to query the device a second time. + 'sh_preempt' is currently the only attr affected. Add checks for other attrs as needed. + ''' + if 'unknown enum:' in hsrp_table['sh_preempt']: + cmd = {'output': 'text', 'command': command.split('|')[0]} + out = run_commands(module, cmd)[0] + hsrp_table['sh_preempt'] = 'enabled' if ('may preempt' in out) else 'disabled' + return hsrp_table + + def get_commands_remove_hsrp(group, interface): commands = ['interface {0}'.format(interface), 'no hsrp {0}'.format(group)] return commands diff --git a/test/integration/targets/nxos_hsrp/tests/common/sanity.yaml b/test/integration/targets/nxos_hsrp/tests/common/sanity.yaml index 83e648b50d..cb09438c4c 100644 --- a/test/integration/targets/nxos_hsrp/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_hsrp/tests/common/sanity.yaml @@ -9,7 +9,7 @@ - block: - name: "Enable feature hsrp" - nxos_feature: + nxos_feature: feature: hsrp provider: "{{ connection }}" state: enabled @@ -155,7 +155,7 @@ always: - name: "Disable feature hsrp" - nxos_feature: + nxos_feature: feature: hsrp provider: "{{ connection }}" state: disabled