PaloAltoNetworks / panos-ansible-upgrade-downgrade

Ansible playbook to license the NGFW, install content updates, and install the required software version
MIT License
7 stars 8 forks source link

PANOS Upgrade fails with PanOSVersion instance has no attribute 'version' #2

Open nacho26 opened 3 years ago

nacho26 commented 3 years ago

Describe the bug

Error during PANOS Download

Expected behavior

Download Major Version

Current behavior

TASK [Kicking off Upgrade / Downgrade Plan] ***** included: /home/user/panos-ansible-upgrade-downgrade/tasks/install_panos_version.yml for localhost => (item=10.0.0)

TASK [Download PAN-OS Major version] **** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: PanOSVersion instance has no attribute 'version' fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/home/user/.ansible/tmp/ansible-tmp-1621031747.84-1797-4967044776330/AnsiballZ_panos_software.py\", line 102, in \n _ansiballz_main()\n File \"/home/user/.ansible/tmp/ansible-tmp-1621031747.84-1797-4967044776330/AnsiballZ_panos_software.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/user/.ansible/tmp/ansible-tmp-1621031747.84-1797-4967044776330/AnsiballZ_panos_software.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_software', init_globals=None, run_name='main', alter_sys=True)\n File \"/usr/lib/python2.7/runpy.py\", line 188, in run_module\n fname, loader, pkg_name)\n File \"/usr/lib/python2.7/runpy.py\", line 82, in _run_module_code\n mod_name, mod_fname, mod_loader, pkg_name)\n File \"/usr/lib/python2.7/runpy.py\", line 72, in _run_code\n exec code in run_globals\n File \"/tmp/ansible_paloaltonetworks.panos.panos_software_payload_WNCO9j/ansible_paloaltonetworks.panos.panos_software_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_software.py\", line 223, in \n File \"/tmp/ansible_paloaltonetworks.panos.panos_software_payload_WNCO9j/ansible_paloaltonetworks.panos.panos_software_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_software.py\", line 182, in main\n File \"/home/user/.local/lib/python2.7/site-packages/panos/init.py\", line 210, in ne\n return not self.eq(other)\n File \"/home/user/.local/lib/python2.7/site-packages/panos/init.py\", line 199, in eq\n if self.mainrelease != other.mainrelease:\n File \"/home/user/.local/lib/python2.7/site-packages/panos/init.py\", line 138, in mainrelease\n return self.version[0:3]\nAttributeError: PanOSVersion instance has no attribute 'version'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP ** localhost : ok=18 changed=2 unreachable=0 failed=1 skipped=6 rescued=0 ignored=0 PLAY RECAP ** localhost : ok=18 changed=2 unreachable=0 failed=1 skipped=6 rescued=0 ignored=0

Possible solution

Steps to reproduce

1. 2. 3. 4.

Screenshots

Context

Your Environment

nacho26 commented 3 years ago

You see that error only with pan-os-ansible version 2.6.0 with 2.5.0 it works.

There is a new feature in 2.6.0 :

panos_software: Download new base version automatically for upgrades

I think this is the issue

nacho26 commented 3 years ago

Problem was only with Debian 10. with Ubuntu 20.04 it worked

nacho26 commented 3 years ago

Sorry Problem still there with pan-os-ansible 2.6.0

nembery commented 3 years ago

hi @nacho26 I'll look into this. Thanks for the report

nembery commented 3 years ago

Hi again @nacho26 I just confirmed this all works as expected on Python3. It looks like you are running this with Python2.7, which is no longer supported. Can you try this again using an updated version of Python?

nacho26 commented 3 years ago

@nembery thank you. I use Ubuntu 20.04 and only Python 3.8.5 is installed. Do you run the test with pan-os-ansible 2.6.0? I have no issues with pan-os-nsible 2.5.0 but with 2.6.0 and this script.

nembery commented 3 years ago

@nacho26 I only mention python2.7 because it is showing up in the traceback you posted above:

/home/user/.local/lib/python2.7/site-packages/panos/init.py

Looks like it's installed in the .local directory. If you have modified the inventory.yml file, you might need to specify to use the python3 interpreter if possible.

nacho26 commented 3 years ago

Sorry I swichted to Ubuntu 20.04 here I have still the issue and no python2 at all:

dpkg -l | grep python ii libpython3-dev:amd64 3.8.2-0ubuntu2 amd64 header files and a static library for Python (default) ii libpython3-stdlib:amd64 3.8.2-0ubuntu2 amd64 interactive high-level object-oriented language (default python3 version) ii libpython3.8:amd64 3.8.5-1~20.04.2 amd64 Shared Python runtime library (version 3.8) ii libpython3.8-dev:amd64 3.8.5-1~20.04.2 amd64 Header files and a static library for Python (v3.8) ii libpython3.8-minimal:amd64 3.8.5-1~20.04.2 amd64 Minimal subset of the Python language (version 3.8) ii libpython3.8-stdlib:amd64 3.8.5-1~20.04.2 amd64 Interactive high-level object-oriented language (standard library, version 3.8) ii python-apt-common 2.0.0ubuntu0.20.04.4 all Python interface to libapt-pkg (locales) ii python-pip-whl 20.0.2-5ubuntu1.5 all Python package installer ii python3 3.8.2-0ubuntu2 amd64 interactive high-level object-oriented language (default python3 version) ii python3-apport 2.20.11-0ubuntu27.17 all Python 3 library for Apport crash report handling ii python3-apt 2.0.0ubuntu0.20.04.4 amd64 Python 3 interface to libapt-pkg ii python3-argcomplete 1.8.1-1.3ubuntu1 all bash tab completion for argparse (for Python 3) ii python3-attr 19.3.0-2 all Attributes without boilerplate (Python 3) ii python3-automat 0.8.0-1ubuntu1 all Self-service finite-state machines for the programmer on the go ii python3-blinker 1.4+dfsg1-0.3ubuntu1 all fast, simple object-to-object and broadcast signaling library ii python3-certifi 2019.11.28-1 all root certificates for validating SSL certs and verifying TLS hosts (python3) ii python3-cffi-backend 1.14.0-1build1 amd64 Foreign Function Interface for Python 3 calling C code - runtime ii python3-chardet 3.0.4-4build1 all universal character encoding detector for Python3 ii python3-click 7.0-3 all Wrapper around optparse for command line utilities - Python 3.x ii python3-colorama 0.4.3-1build1 all Cross-platform colored terminal text in Python - Python 3.x ii python3-commandnotfound 20.04.4 all Python 3 bindings for command-not-found. ii python3-configobj 5.0.6-4 all simple but powerful config file reader and writer for Python 3 ii python3-constantly 15.1.0-1build1 all Symbolic constants in Python ii python3-crypto 2.6.1-13ubuntu2 amd64 cryptographic algorithms and protocols for Python 3 ii python3-cryptography 2.8-3ubuntu0.1 amd64 Python library exposing cryptographic recipes and primitives (Python 3) ii python3-dbus 1.2.16-1build1 amd64 simple interprocess messaging system (Python 3 interface) ii python3-debconf 1.5.73 all interact with debconf from Python 3 ii python3-debian 0.1.36ubuntu1 all Python 3 modules to work with Debian-related data formats ii python3-dev 3.8.2-0ubuntu2 amd64 header files and a static library for Python (default) ii python3-distro 1.4.0-1 all Linux OS platform information API ii python3-distro-info 0.23ubuntu1 all information about distributions' releases (Python 3 module) ii python3-distupgrade 1:20.04.32 all manage release upgrades ii python3-distutils 3.8.5-1~20.04.1 all distutils package for Python 3.x ii python3-dnspython 1.16.0-1build1 all DNS toolkit for Python 3 ii python3-entrypoints 0.3-2ubuntu1 all Discover and load entry points from installed packages (Python 3) ii python3-gdbm:amd64 3.8.5-1~20.04.1 amd64 GNU dbm database support for Python 3.x ii python3-gi 3.36.0-1 amd64 Python 3 bindings for gobject-introspection libraries ii python3-hamcrest 1.9.0-3 all Hamcrest framework for matcher objects (Python 3) ii python3-httplib2 0.14.0-1ubuntu1 all comprehensive HTTP client library written for Python3 ii python3-hyperlink 19.0.0-1 all Immutable, Pythonic, correct URLs. ii python3-idna 2.8-1 all Python IDNA2008 (RFC 5891) handling (Python 3) ii python3-importlib-metadata 1.5.0-1 all library to access the metadata for a Python package - Python 3.x ii python3-incremental 16.10.1-3.2 all Library for versioning Python projects. ii python3-jinja2 2.10.1-2 all small but fast and easy to use stand-alone template engine ii python3-jmespath 0.9.4-2 all JSON Matching Expressions (Python 3) ii python3-json-pointer 2.0-0ubuntu1 all resolve JSON pointers - Python 3.x ii python3-jsonpatch 1.23-3 all library to apply JSON patches - Python 3.x ii python3-jsonschema 3.2.0-0ubuntu2 all An(other) implementation of JSON Schema (Draft 3 and 4) - Python 3.x ii python3-jwt 1.7.1-2ubuntu2 all Python 3 implementation of JSON Web Token ii python3-kerberos 1.1.14-3.1build1 amd64 GSSAPI interface module - Python 3.x ii python3-keyring 18.0.1-2ubuntu1 all store and access your passwords safely - Python 3 version of the package ii python3-launchpadlib 1.10.13-1 all Launchpad web services client library (Python 3) ii python3-lazr.restfulclient 0.14.2-2build1 all client for lazr.restful-based web services (Python 3) ii python3-lazr.uri 1.0.3-4build1 all library for parsing, manipulating, and generating URIs ii python3-lib2to3 3.8.5-1~20.04.1 all Interactive high-level object-oriented language (lib2to3) ii python3-libcloud 2.8.0-1 all unified Python interface into the cloud (Python3 version) ii python3-lockfile 1:0.12.2-2ubuntu2 all file locking library for Python — Python 3 library ii python3-markupsafe 1.1.0-1build2 amd64 HTML/XHTML/XML string library for Python 3 ii python3-minimal 3.8.2-0ubuntu2 amd64 minimal subset of the Python language (default python3 version) ii python3-more-itertools 4.2.0-1build1 all library with routines for operating on iterables, beyond itertools (Python 3) ii python3-nacl 1.3.0-5 amd64 Python bindings to libsodium (Python 3) ii python3-netaddr 0.7.19-3 all manipulation of various common network address notations (Python 3) ii python3-netifaces 0.10.4-1ubuntu4 amd64 portable network interface information - Python 3.x ii python3-newt:amd64 0.52.21-4ubuntu2 amd64 NEWT module for Python3 ii python3-ntlm-auth 1.1.0-1 all NTLM low-level Python library ii python3-oauthlib 3.1.0-1ubuntu2 all generic, spec-compliant implementation of OAuth for Python3 ii python3-openssl 19.0.0-1build1 all Python 3 wrapper around the OpenSSL library ii python3-pexpect 4.6.0-1build1 all Python 3 module for automating interactive applications ii python3-pip 20.0.2-5ubuntu1.5 all Python package installer ii python3-pkg-resources 45.2.0-1 all Package Discovery and Resource Access using pkg_resources ii python3-problem-report 2.20.11-0ubuntu27.17 all Python 3 library to handle problem reports ii python3-ptyprocess 0.6.0-1ubuntu1 all Run a subprocess in a pseudo terminal from Python 3 ii python3-pyasn1 0.4.2-3build1 all ASN.1 library for Python (Python 3 module) ii python3-pyasn1-modules 0.2.1-0.2build1 all Collection of protocols modules written in ASN.1 language (Python 3) ii python3-pymacaroons 0.13.0-3 all Macaroon library for Python 3 ii python3-pyrsistent:amd64 0.15.5-1build1 amd64 persistent/functional/immutable data structures for Python ii python3-requests 2.22.0-2ubuntu1 all elegant and simple HTTP library for Python3, built for human beings ii python3-requests-kerberos 0.12.0-2 all Kerberos/GSSAPI authentication handler for python-requests - Python 3.x ii python3-requests-ntlm 1.1.0-1 all Adds support for NTLM authentication to the requests library ii python3-requests-unixsocket 0.2.0-2 all Use requests to talk HTTP via a UNIX domain socket - Python 3.x ii python3-secretstorage 2.3.1-2ubuntu1 all Python module for storing secrets - Python 3.x version ii python3-selinux 3.0-1build2 amd64 Python3 bindings to SELinux shared libraries ii python3-serial 3.4-5.1 all pyserial - module encapsulating access for the serial port ii python3-service-identity 18.1.0-5build1 all Service identity verification for pyOpenSSL (Python 3 module) ii python3-setuptools 45.2.0-1 all Python3 Distutils Enhancements ii python3-simplejson 3.16.0-2ubuntu2 amd64 simple, fast, extensible JSON encoder/decoder for Python 3.x ii python3-six 1.14.0-2 all Python 2 and 3 compatibility library (Python 3 interface) ii python3-software-properties 0.98.9.5 all manage the repositories that you install software from ii python3-systemd 234-3build2 amd64 Python 3 bindings for systemd ii python3-twisted 18.9.0-11ubuntu0.20.04.1 all Event-based framework for internet applications ii python3-twisted-bin:amd64 18.9.0-11ubuntu0.20.04.1 amd64 Event-based framework for internet applications ii python3-update-manager 1:20.04.10.7 all python 3.x module for update-manager ii python3-urllib3 1.25.8-2ubuntu0.1 all HTTP library with thread-safe connection pooling for Python3 ii python3-wadllib 1.3.3-3build1 all Python 3 library for navigating WADL files ii python3-wheel 0.34.2-1 all built-package format for Python ii python3-winrm 0.3.0-2 all Python 3 library for Windows Remote Management ii python3-xmltodict 0.12.0-1 all Makes working with XML feel like you are working with JSON (Python 3) ii python3-yaml 5.3.1-1ubuntu0.1 amd64 YAML parser and emitter for Python3 ii python3-zipp 1.0.0-1 all pathlib-compatible Zipfile object wrapper - Python 3.x ii python3-zope.interface 4.7.1-1 amd64 Interfaces for Python3 ii python3.8 3.8.5-1~20.04.2 amd64 Interactive high-level object-oriented language (version 3.8) ii python3.8-dev 3.8.5-1~20.04.2 amd64 Header files and a static library for Python (v3.8) ii python3.8-minimal 3.8.5-1~20.04.2 amd64 Minimal subset of the Python language (version 3.8)

nembery commented 3 years ago

Hi @nacho26 can you send the ansible error output with Python3?

nacho26 commented 3 years ago

@nembery sure, thank you:

TASK [Install PAN-OS Minor version and Reboot] ** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'PanOSVersion' object has no attribute 'version' fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/home/user/.ansible/tmp/ansible-tmp-1621946219.239189-138193094642097/AnsiballZ_panos_software.py\", line 102, in \n _ansiballz_main()\n File \"/home/user/.ansible/tmp/ansible-tmp-1621946219.239189-138193094642097/AnsiballZ_panos_software.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/user/.ansible/tmp/ansible-tmp-1621946219.239189-138193094642097/AnsiballZ_panos_software.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_software', init_globals=None, run_name='main', alter_sys=True)\n File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_paloaltonetworks.panos.panos_software_payload_2j56q34a/ansible_paloaltonetworks.panos.panos_software_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_software.py\", line 223, in \n File \"/tmp/ansible_paloaltonetworks.panos.panos_software_payload_2j56q34a/ansible_paloaltonetworks.panos.panos_software_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_software.py\", line 182, in main\n File \"/home/user/.local/lib/python3.8/site-packages/panos/init.py\", line 210, in ne\n return not self.eq(other)\n File \"/home/user/.local/lib/python3.8/site-packages/panos/init.py\", line 199, in eq\n if self.mainrelease != other.mainrelease:\n File \"/home/user/.local/lib/python3.8/site-packages/panos/init.py\", line 138, in mainrelease\n return self.version[0:3]\nAttributeError: 'PanOSVersion' object has no attribute 'version'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

smigii commented 1 year ago

@nembery is there any update on this? I am currently getting the same error

/var/folders/sb/wzby_gw52ybcdk_xzvfnmg2w0000gp/T/ansible_paloaltonetworks.panos.panos_software_payload_ia1b1v9h/ansible_paloaltonetworks.panos.panos_software_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_software.py:172: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
/var/folders/sb/wzby_gw52ybcdk_xzvfnmg2w0000gp/T/ansible_paloaltonetworks.panos.panos_software_payload_ia1b1v9h/ansible_paloaltonetworks.panos.panos_software_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_software.py:179: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
Traceback (most recent call last):
  File "/Users/XXXXX/.ansible/tmp/ansible-tmp-1670018746.698667-13801-38660490920878/AnsiballZ_panos_software.py", line 107, in <module>
    _ansiballz_main()
  File "/Users/XXXXX/.ansible/tmp/ansible-tmp-1670018746.698667-13801-38660490920878/AnsiballZ_panos_software.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/Users/XXXXX/.ansible/tmp/ansible-tmp-1670018746.698667-13801-38660490920878/AnsiballZ_panos_software.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_software', init_globals=dict(_module_fqn='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_software', _modlib_path=modlib_path),
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 224, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/var/folders/sb/wzby_gw52ybcdk_xzvfnmg2w0000gp/T/ansible_paloaltonetworks.panos.panos_software_payload_ia1b1v9h/ansible_paloaltonetworks.panos.panos_software_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_software.py", line 229, in <module>
  File "/var/folders/sb/wzby_gw52ybcdk_xzvfnmg2w0000gp/T/ansible_paloaltonetworks.panos.panos_software_payload_ia1b1v9h/ansible_paloaltonetworks.panos.panos_software_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_software.py", line 188, in main
  File "/opt/homebrew/lib/python3.10/site-packages/panos/__init__.py", line 223, in __ne__
    return not self.__eq__(other)
  File "/opt/homebrew/lib/python3.10/site-packages/panos/__init__.py", line 212, in __eq__
    if self.mainrelease != other.mainrelease:
  File "/opt/homebrew/lib/python3.10/site-packages/panos/__init__.py", line 151, in mainrelease
    return self.version[0:3]
AttributeError: 'PanOSVersion' object has no attribute 'version'
smigii commented 1 year ago

If anyone else has this issue, I have opened a pull request for a fix here - https://github.com/PaloAltoNetworks/pan-os-ansible/pull/363

jamesholland-uk commented 1 year ago

@smigii That PR is now merged and released in 2.13.0 if you want to re-test?