From 4239464f150aed1da1ee41b951ae18da49e010bb Mon Sep 17 00:00:00 2001 From: Jacob McGill <9847006+jmcgill298@users.noreply.github.com> Date: Thu, 19 Nov 2020 14:26:47 -0500 Subject: [PATCH] Add support Ansible2.10+ (#263) --- CHANGELOG.md | 4 ++++ README.md | 8 ++++++-- library/ntc_config_command.py | 7 ++++++- library/ntc_show_command.py | 8 +++++++- setup.py | 7 ++++--- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6abdb0d..019224a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.9.3] +### Fixed +- [#262] Account for Ansible Versions beyond 2.9 + ## [0.9.2] ### Fixed - [#256] Made setup.py work with python2.7 again diff --git a/README.md b/README.md index ec445ee..44b2cc9 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,11 @@ pip install terminal ## Common Issues -#### Gather Facts +### Ansible 2.10 + +In order to use this with Ansible 2.10 and greater, the `packaging` python library must be installed. + +### Gather Facts Starting in Ansible 2.1 there is a name space conflict when gathering facts. The below message will indicate the issues: @@ -141,7 +145,7 @@ rm ./ntc-templates/setup.py ``` See https://github.com/ansible/ansible/issues/20702 and https://github.com/ansible/ansible/pull/20717 for further details. -#### This module requires TextFSM +### This module requires TextFSM Most often seen in virtual enviroments as per ansible's interpretation of which python binary you are using is not as expected. You can tell that you have reached this issue if you correctly have textfsm installed, but receive the following warning: diff --git a/library/ntc_config_command.py b/library/ntc_config_command.py index 00a8bb5..74c669f 100644 --- a/library/ntc_config_command.py +++ b/library/ntc_config_command.py @@ -142,7 +142,12 @@ from ansible import __version__ as ansible_version -if float(ansible_version[:3]) < 2.4: +try: + from packaging import version + HAS_PACKAGING=True +except ImportError: + HAS_PACKAGING=False +if (HAS_PACKAGING and version.parse(ansible_version) < version.parse("2.4")) or (not HAS_PACKAGING and float(ansible_version[:3]) < 2.4): raise ImportError("Ansible versions < 2.4 are not supported") diff --git a/library/ntc_show_command.py b/library/ntc_show_command.py index cfabb7d..1a092ab 100644 --- a/library/ntc_show_command.py +++ b/library/ntc_show_command.py @@ -232,8 +232,14 @@ import os.path import socket +try: + from packaging import version + HAS_PACKAGING = True +except ImportError: + HAS_PACKAGING = False from ansible import __version__ as ansible_version -if float(ansible_version[:3]) < 2.4: + +if (HAS_PACKAGING and version.parse(ansible_version) < version.parse("2.4")) or (not HAS_PACKAGING and float(ansible_version[:3]) < 2.4): raise ImportError("Ansible versions < 2.4 are not supported") HAS_NTC_TEMPLATES = True diff --git a/setup.py b/setup.py index 4e65d5c..81510b4 100644 --- a/setup.py +++ b/setup.py @@ -9,17 +9,18 @@ setup( name='ntc-ansible', packages=find_packages(), - version='0.9.2', + version='0.9.3', description='Dependencies for NTC Ansible modules', long_description=README, long_description_content_type="text/markdown", author='Jason Edelman', author_email='jedelman8@gmail.com', url='https://github.com/networktocode/ntc-ansible', - download_url='https://github.com/networktocode/ntc-ansible/tarball/0.1.0', + download_url='https://github.com/networktocode/ntc-ansible/tarball/0.9.3', install_requires=[ 'pynxos', 'pyntc', - 'netmiko' + 'netmiko', + 'packaging', ], )