bugfix icx_system.py UnboundLocalError: local variable 'hostname' referenced before assignment #436
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
Testing against a config with the following items fail:
tacacs-server enable vlan 10
tacacs-server host 100.100.100.1
tacacs-server key 2 $SomeEncryptedKey
Setting hostname to 'None', as was done for other k:v pairs in parse_aaa_servers allows correct parsing, script completion and ansible playbooks to run successfully.
ISSUE TYPE
COMPONENT NAME
icx_system.py
ADDITIONAL INFORMATION
If parsing an ICX style config without tacacs-server vlan filtering enabled, an unmodified icx_system.py successfully completes and allows the playbooks to finish without error. However if VLAN filtering is enabled then the icx_system.py errors out and ansible playbooks fail for that host.
A switch with the following config works correctly without modifying icx_system.py
A switch with the following config fails due to attempting to map the hostname before it is assigned while parsing the vlan filter line before the host line.
output:
Since the first line parsed is not the host entry then the hostname is never assigned. Setting hostname to 'None' as other attributes are done allows the module to correctly process the aaa config and results in a successful playbook run.
Switch with the following config now completes successfully after the code changes
$ ansible-playbook -i /etc/ansible/inventory/test.yaml /etc/ansible/playbooks/edge/switches.yaml --vault-id user@prompt
PLAY [Configure ALL edge switches] *******************************************************************************************
TASK [edge-switch : Configure Foundry/Brocade/Ruckus hostname] ***************************************************************
changed: []
PLAY RECAP *******************************************************************************************************************
: ok=1 changed=1 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0