Multiple parsing issues when running the nxos_facts module
cpund opened this issue · 2 comments
SUMMARY
When running a simple playbook to extract all of the facts, using cisco.nxos.nxos_facts module (with particular interest in the neighbors), the module silently fails to gather any neighbors, as well as additional weird parsing of some details.
ISSUE TYPE
- Bug Report
COMPONENT NAME
nxos_facts
ANSIBLE VERSION
ansible [core 2.15.6]
config file = None
configured module search path = ['/home/cpund/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/cpund/.local/lib/python3.12/site-packages/ansible
ansible collection location = /home/cpund/.ansible/collections:/usr/share/ansible/collections
executable location = /home/cpund/.local/bin/ansible
python version = 3.12.0 (main, Oct 21 2023, 17:42:12) [GCC 11.4.0] (/usr/bin/python3.12)
jinja version = 3.0.3
libyaml = False
COLLECTION VERSION
# /home/cpund/.ansible/collections/ansible_collections
Collection Version
---------- -------
cisco.nxos 6.0.0
# /home/cpund/.local/lib/python3.12/site-packages/ansible_collections
Collection Version
---------- -------
cisco.nxos 4.4.0
# /usr/lib/python3/dist-packages/ansible_collections
Collection Version
---------- -------
cisco.nxos 1.4.0
CONFIGURATION
CONFIG_FILE() = None
OS / ENVIRONMENT
WSL: 5.15.133.1-microsoft-standard-WSL2
Linux flavor: Ubuntu 22.04.3 LTS
Nexus Supervisor: N77-SUP3E
NX-OS Version: 8.3(2)
STEPS TO REPRODUCE
- name: Save distro facts to a file
hosts: distro
gather_facts: false
vars:
ansible_connection: ansible.netcommon.network_cli
ansible_user: cpund
ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q REDACTED_BASTION"'
- name: Extract data
cisco.nxos.nxos_facts:
gather_subset:
- all
- "!config"
gather_network_resources:
- all
register: result
EXPECTED RESULTS
I expect for data to be properly extracted and parsed, but have noticed multiple issues with the parsing, particular under the ansible_net_neighbors, ansible_net_fan_info, and ansible_net_interfaces sections.
ACTUAL RESULTS
It appears as if the parser is experiencing difficulty in multiple circumstances, as the output indicates that instead of saving the output of the command, it instead saves the command itself. It then tries to parse the saved command (as opposed to the output of it). The Ansible playbook indicates no errors and successfully saves the output to a file as requested later in the playbook. Upon further request, I can work to strip out sensitive information from the -vvvv and post it later.
"ansible_net_interfaces": {
"%": {
"bandwidth": null,
"description": null,
"duplex": null,
"macaddress": null,
"mode": null,
"mtu": null,
"speed": null,
"state": null,
"type": null
},
"show": {
"bandwidth": null,
"description": null,
"duplex": null,
"macaddress": null,
"mode": null,
"mtu": null,
"speed": null,
"state": null,
"type": null
}
},
"ansible_net_fan_info": [
{
"hw_ver": "|",
"model": "environment",
"name": "show",
"status": "json-pretty"
},
{
"hw_ver": "'^'",
"model": "Invalid",
"name": "%",
"status": "marker."
}
],
"ansible_net_neighbors": {},
@cpund I wonder if you are hitting a problem with get_facts that I am with NXOS devices that do not support the "| json-pretty" cli option.
I found this comment in a closed issue regarding timeouts associated with get_facts where the fix involved using "| json-pretty" and falling back to "| json" if the device does not support json-pretty
#637 (comment)
The problem is I don't think the fall back option is working. Before 6.0.0 I was seeing fact data, after the update I only see empty lists in the output without any Ansible failures similar to your explanation.
Interestingly what tipped me off to this issue was the results we see for ansible_net_fan_info as shown below. Which looks like you have as well.
{
"ansible_facts": {
"ansible_net_all_ipv4_addresses": [],
"ansible_net_all_ipv6_addresses": [],
"ansible_net_api": "cliconf",
"ansible_net_fan_info": [
{
"hw_ver": "|",
"model": "environment",
"name": "show",
"status": "json-pretty"
},
{
"hw_ver": "'^'",
"model": "Invalid",
"name": "%",
"status": "marker."
}
],
}
}
@cpund I wonder if you are hitting a problem with get_facts that I am with NXOS devices that do not support the "| json-pretty" cli option.
I found this comment in a closed issue regarding timeouts associated with get_facts where the fix involved using "| json-pretty" and falling back to "| json" if the device does not support json-pretty #637 (comment)
The problem is I don't think the fall back option is working. Before 6.0.0 I was seeing fact data, after the update I only see empty lists in the output without any Ansible failures similar to your explanation.
Interestingly what tipped me off to this issue was the results we see for ansible_net_fan_info as shown below. Which looks like you have as well.
{ "ansible_facts": { "ansible_net_all_ipv4_addresses": [], "ansible_net_all_ipv6_addresses": [], "ansible_net_api": "cliconf", "ansible_net_fan_info": [ { "hw_ver": "|", "model": "environment", "name": "show", "status": "json-pretty" }, { "hw_ver": "'^'", "model": "Invalid", "name": "%", "status": "marker." } ], } }
I can definitely confirm that the issue is with detection of whether or not output is in json or pretty_json. I just commented out the following lines:
cisco.nxos/plugins/module_utils/network/nxos/facts/legacy/base.py
Lines 41 to 44 in 472ae1b
and the facts module ran flawlessly. I've got neighbor information, fan info, interface info, and more! So now to determine why/how it's parsing this incorrectly - still a little rough around the edge debugging ansible modules though. Guessing by the following lines, an Exception is not being raised and thus it never re-attempts with plain old "| json".
Edit: Further research, it seems like on my version/model combo of NX-OS, | json
was pretty printed, and later on, Cisco changed functionality of | json
to be minified, introducing | json-pretty
to fulfill the pretty-print capabilities.