Workaround prompt issues between ROS 6.49 and 7.1.5 (#62) (#161)

* Prompt support for ROS 6.49+ (#62)

* More precise version match (#62)

* Add changelog fragment and lint (#62)

* Update changelogs/fragments/161-workaround-prompt-with-space.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Vendor version package to support older ansible versions (#62)

* Update plugins/module_utils/routeros.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/module_utils/routeros.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* move PSF-2.0.txt to LICENSES folder

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Sam Grimee - LX2SG 2023-03-23 21:25:23 +01:00 committed by GitHub
parent 4329928474
commit c1a6ae8658
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 428 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import json
from ansible.module_utils.common.text.converters import to_native
from ansible.module_utils.basic import env_fallback
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list, ComplexList
from ansible_collections.community.routeros.plugins.module_utils.version import LooseVersion
from ansible.module_utils.connection import Connection, ConnectionError
_DEVICE_CONFIGS = {}
@ -103,6 +104,16 @@ def to_commands(module, commands):
return transform(commands)
def should_add_leading_space(module):
"""Determines whether adding a leading space to the command is needed
to workaround prompt bug in 6.49 <= ROS < 7.2"""
capabilities = get_capabilities(module)
network_os_version = capabilities.get('device_info', {}).get('network_os_version')
if network_os_version is None:
return False
return LooseVersion('6.49') <= LooseVersion(network_os_version) < LooseVersion('7.2')
def run_commands(module, commands, check_rc=True):
responses = list()
connection = get_connection(module)
@ -117,6 +128,9 @@ def run_commands(module, commands, check_rc=True):
prompt = None
answer = None
if should_add_leading_space(module):
command = " " + command
try:
out = connection.get(command, prompt, answer)
except ConnectionError as exc: