diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2018-07-31 13:04:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-31 13:04:05 -0400 |
commit | 222c907ffbc2fb8d611cfdc5a83954f62b88f2c6 (patch) | |
tree | 1997a7260d4ac9c60ba6c96086305f64d3cee72d /lib/ansible/playbook | |
parent | b3c054c55eb96420af747c54dcd9bc89f01a3fb8 (diff) | |
download | ansible-222c907ffbc2fb8d611cfdc5a83954f62b88f2c6.tar.gz |
actually check we can run scm command for roles (#43315)
* actually check we can run scm command for roles
* a better error message than file not found
* more narrow exception hanlding
* refactor common functions for more extended use and further 'basic.py' separation
Diffstat (limited to 'lib/ansible/playbook')
-rw-r--r-- | lib/ansible/playbook/role/requirement.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/ansible/playbook/role/requirement.py b/lib/ansible/playbook/role/requirement.py index f41bf8968f..fb59a3dba5 100644 --- a/lib/ansible/playbook/role/requirement.py +++ b/lib/ansible/playbook/role/requirement.py @@ -28,6 +28,7 @@ from subprocess import Popen, PIPE from ansible import constants as C from ansible.errors import AnsibleError from ansible.module_utils._text import to_native +from ansible.module_utils.common.process import get_bin_path from ansible.module_utils.six import string_types from ansible.playbook.role.definition import RoleDefinition @@ -203,12 +204,17 @@ class RoleRequirement(RoleDefinition): if scm not in ['hg', 'git']: raise AnsibleError("- scm %s is not currently supported" % scm) + try: + scm_path = get_bin_path(scm) + except (ValueError, OSError, IOError): + raise AnsibleError("could not find/use %s, it is required to continue with installing %s" % (scm, src)) + tempdir = tempfile.mkdtemp(dir=C.DEFAULT_LOCAL_TMP) - clone_cmd = [scm, 'clone', src, name] + clone_cmd = [scm_path, 'clone', src, name] run_scm_cmd(clone_cmd, tempdir) if scm == 'git' and version: - checkout_cmd = [scm, 'checkout', version] + checkout_cmd = [scm_path, 'checkout', version] run_scm_cmd(checkout_cmd, os.path.join(tempdir, name)) temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.tar', dir=C.DEFAULT_LOCAL_TMP) @@ -218,12 +224,12 @@ class RoleRequirement(RoleDefinition): with tarfile.open(temp_file.name, "w") as tar: tar.add(os.path.join(tempdir, name), arcname=name) elif scm == 'hg': - archive_cmd = ['hg', 'archive', '--prefix', "%s/" % name] + archive_cmd = [scm_path, 'archive', '--prefix', "%s/" % name] if version: archive_cmd.extend(['-r', version]) archive_cmd.append(temp_file.name) elif scm == 'git': - archive_cmd = ['git', 'archive', '--prefix=%s/' % name, '--output=%s' % temp_file.name] + archive_cmd = [scm_path, 'archive', '--prefix=%s/' % name, '--output=%s' % temp_file.name] if version: archive_cmd.append(version) else: |