napalm-automation/napalm-ansible

napalm module : Error: "'ascii' codec can't encode characters in position 5396-5398: ordinal not in range(128)"}

pranayp1687 opened this issue · 14 comments

Hi ,

We are getting below error when we used napalm_cli module, it's working most of same model firewall device but for some getting below error.
Can you please help.

TASK [rancid : running config command] *****************************************
fatal: [XN-SINCC3-BO105 -> localhost]: FAILED! => {"changed": false, "msg": "'ascii' codec can't encode character u'\\x93' in position 1364: ordinal not in range(128)"}
...ignoring
fatal: [XN-SINCC3-BO101 -> localhost]: FAILED! => {"changed": false, "msg": "'ascii' codec can't encode characters in position 1249-1251: ordinal not in range(128)"}
...ignoring
fatal: [XN-SINTP1-BO101 -> localhost]: FAILED! => {"changed": false, "msg": "'ascii' codec can't encode characters in position 8270-8272: ordinal not in range(128)"}
...ignoring
fatal: [XN-SINGS1-BO301 -> localhost]: FAILED! => {"changed": false, "msg": "xmlSAX2Characters: huge text node, line 116061, column 92 (line 116061)"}
...ignoring
fatal: [XN-SINPL1-BO101 -> localhost]: FAILED! => {"changed": false, "msg": "'ascii' codec can't encode character u'\\xa0' in position 9914: ordinal not in range(128)"}
...ignoring
fatal: [XN-PAOEQ1-BO101 -> localhost]: FAILED! => {"changed": false, "msg": "'ascii' codec can't encode characters in position 5396-5398: ordinal not in range(128)"}
...ignoring
fatal: [XN-LAXOW1-BO101 -> localhost]: FAILED! => {"changed": false, "msg": "'ascii' codec can't encode characters in position 9431-9433: ordinal not in range(128)"}
...ignoring
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 24: ordinal not in range(128)
fatal: [XNL-HKGCW1-BO104 -> localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1693454675.85-62343020719071/AnsiballZ_napalm_cli.py\", line 102, in \n _ansiballz_main()\n File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1693454675.85-62343020719071/AnsiballZ_napalm_cli.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1693454675.85-62343020719071/AnsiballZ_napalm_cli.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible.modules.napalm_cli', init_globals=None, run_name='main', alter_sys=True)\n File \"/usr/lib64/python2.7/runpy.py\", line 176, in run_module\n fname, loader, pkg_name)\n File \"/usr/lib64/python2.7/runpy.py\", line 82, in _run_module_code\n mod_name, mod_fname, mod_loader, pkg_name)\n File \"/usr/lib64/python2.7/runpy.py\", line 72, in _run_code\n exec code in run_globals\n File \"/tmp/ansible_napalm_cli_payload_egSM2v/ansible_napalm_cli_payload.zip/ansible/modules/napalm_cli.py\", line 191, in \n File \"/tmp/ansible_napalm_cli_payload_egSM2v/ansible_napalm_cli_payload.zip/ansible/modules/napalm_cli.py\", line 175, in main\nUnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 24: ordinal not in range(128)\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
...ignoring

Below is Playbook task, below variable value we are kept in another file, so ignore that part:

- name: running config command
  napalm_cli:
    hostname: "{{ ansible_host }}"
    username: "{{ ansible_user }}"
    dev_os: "{{ ansible_network_os }}"
    password: "{{ ansible_password }}"
    args:
      commands: "{{ commands_list }}"
  register: configuration
  # retries: 3
  # delay: 3
  # until: configuration is not failed
  ignore_errors: true
  delegate_to: localhost

You probably need to post the contents of commands_list (i.e. the commands you are trying to execute).

Hi,
Thanks for reply, below are commands:

show chassis environment | no-more
show chassis firmware | no-more
show chassis fpc detail | no-more" }
show chassis hardware detail | no-more
show chassis hardware models | no-more
show chassis routing-engine | no-more
show chassis alarms | no-more
show system license | no-more
show system boot-messages | no-more
show system core-dumps | no-more
show version detail | no-more
show version invoke-on other-routing-engine | no-more
show configuration | no-more
show configuration | count | no-more
show configuration | display set | no-more
show interfaces descriptions | no-more
show interfaces terse | except "aenet|inet" | match "^xe-" | count
show interfaces descriptions | except "aenet|inet" | match "^xe-" | count
show interfaces terse | except "aenet|inet" | match "^ge-" | count
show interfaces descriptions | except "aenet|inet" | match "^ge-" | count
show interfaces terse | except "aenet|inet" | match "^et-" | count
show interfaces descriptions | except "aenet|inet" | match "^et-" | count
show chassis fabric summary | no-more
show system resource-monitor fpc | no-more
show system process summary | no-more
show route summary | no-more

Also find the sheet which mention playbook working for devices and not working for devices model and version.

Working and nonworking devices model and version.xlsx

bewing commented

I have to ask some silly questions:
Do you have any UTF-8 characters in your running config? (Japanese kanji, Chinese script, etc)
Are you using Python2 or Python3 in your execution environment?

@pranayp1687

What do you mean you are using Python2? napalm doesn't support python2.

We are using python 2 

Okay, current versions of napalm are not intended to work with Python2. So if they do, it is by luck/chance.

I am going to close this as it doesn't sound like there is an issue using Python3.

Even I used python3 and python 3.8, Its not working. Please susggest

Yeah, Python 3.8 is fine.

Same error or something different?

So you need to pick one device that is failing consistently and then isolate which particular command is failing (from your above command_list). I would probably look at: show configuration | no-more, but you will need to isolate which command is failing.

As @bewing mentioned have you verified that there are no non-ASCII characters in the output (particularly embedded in your config).

Okay, I am just going to close this. You are not providing enough information to assist you (and it very likely is not a napalm issue).