mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Handle downstream version additions (#22428)
Some downstreams want to ship multiple versions of ansible (Either to have multiple ansible versions or to have a version that uses python3.X and a version that uses python2.x). When they do this, they append a version number to the cli scripts in /usr/bin. This patch will remove those version numbers before trying to find the ansible python module to import for this commandline
This commit is contained in:
parent
4ca7726e75
commit
9ff03e6c1e
1 changed files with 16 additions and 10 deletions
16
bin/ansible
16
bin/ansible
|
@ -69,17 +69,23 @@ if __name__ == '__main__':
|
||||||
display.debug("starting run")
|
display.debug("starting run")
|
||||||
|
|
||||||
sub = None
|
sub = None
|
||||||
try:
|
|
||||||
if me.find('-') != -1:
|
|
||||||
target = me.split('-')
|
target = me.split('-')
|
||||||
|
if target[-1][0].isdigit():
|
||||||
|
# Remove any version or pthon version info as downstreams
|
||||||
|
# sometimes add that
|
||||||
|
target = target[:-1]
|
||||||
|
|
||||||
if len(target) > 1:
|
if len(target) > 1:
|
||||||
sub = target[1]
|
sub = target[1]
|
||||||
myclass = "%sCLI" % sub.capitalize()
|
myclass = "%sCLI" % sub.capitalize()
|
||||||
mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
|
elif target[0] == 'ansible':
|
||||||
elif me == 'ansible':
|
sub = 'adhoc'
|
||||||
from ansible.cli.adhoc import AdHocCLI as mycli
|
myclass = 'AdHocCLI'
|
||||||
else:
|
else:
|
||||||
raise AnsibleError("Unknown Ansible alias: %s" % me)
|
raise AnsibleError("Unknown Ansible alias: %s" % me)
|
||||||
|
|
||||||
|
try:
|
||||||
|
mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
# ImportError members have changed in py3
|
# ImportError members have changed in py3
|
||||||
if 'msg' in dir(e):
|
if 'msg' in dir(e):
|
||||||
|
|
Loading…
Reference in a new issue