summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2017-03-10 12:01:11 -0800
committerGitHub <noreply@github.com>2017-03-10 12:01:11 -0800
commit9ff03e6c1ed1e578807433d032d9e78c42d199c5 (patch)
tree8c5e93bed65c20b9eec36783758e2b70c1de60ce
parent4ca7726e7590972e775408ee99a62cd51f9598a6 (diff)
downloadansible-9ff03e6c1ed1e578807433d032d9e78c42d199c5.tar.gz
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
-rwxr-xr-xbin/ansible26
1 files changed, 16 insertions, 10 deletions
diff --git a/bin/ansible b/bin/ansible
index 22dd449d3f..24550b92e9 100755
--- a/bin/ansible
+++ b/bin/ansible
@@ -69,17 +69,23 @@ if __name__ == '__main__':
display.debug("starting run")
sub = None
+ 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:
+ sub = target[1]
+ myclass = "%sCLI" % sub.capitalize()
+ elif target[0] == 'ansible':
+ sub = 'adhoc'
+ myclass = 'AdHocCLI'
+ else:
+ raise AnsibleError("Unknown Ansible alias: %s" % me)
+
try:
- if me.find('-') != -1:
- target = me.split('-')
- if len(target) > 1:
- sub = target[1]
- myclass = "%sCLI" % sub.capitalize()
- mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
- elif me == 'ansible':
- from ansible.cli.adhoc import AdHocCLI as mycli
- else:
- raise AnsibleError("Unknown Ansible alias: %s" % me)
+ mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
except ImportError as e:
# ImportError members have changed in py3
if 'msg' in dir(e):