diff --git a/changelogs/fragments/72321_git.yml b/changelogs/fragments/72321_git.yml new file mode 100644 index 00000000000..8ba0ca7558c --- /dev/null +++ b/changelogs/fragments/72321_git.yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- git - check if git version is available or not before using it for comparison (https://github.com/ansible/ansible/issues/72321). diff --git a/lib/ansible/modules/git.py b/lib/ansible/modules/git.py index 26d4c59f924..f4a8a764419 100644 --- a/lib/ansible/modules/git.py +++ b/lib/ansible/modules/git.py @@ -500,7 +500,7 @@ def set_git_ssh_env(key_file, ssh_opts, git_version, module): # older than 2.3 does not know how to use git_ssh_command, # so we force it into get_ssh var # https://github.com/gitster/git/commit/09d60d785c68c8fa65094ecbe46fbc2a38d0fc1f - if git_version < LooseVersion('2.3.0'): + if git_version is not None and git_version < LooseVersion('2.3.0'): # for use in wrapper os.environ["GIT_SSH_OPTS"] = ssh_opts @@ -913,7 +913,7 @@ def fetch(git_path, module, repo, dest, version, remote, depth, bare, refspec, g refspecs = ['+refs/heads/*:refs/heads/*', '+refs/tags/*:refs/tags/*'] else: # ensure all tags are fetched - if git_version_used >= LooseVersion('1.9'): + if git_version_used is not None and git_version_used >= LooseVersion('1.9'): fetch_cmd.append('--tags') else: # old git versions have a bug in --tags that prevents updating existing tags @@ -1308,7 +1308,7 @@ def main(): # GIT_SSH= as an environment variable, might create sh wrapper script for older versions. set_git_ssh_env(key_file, ssh_opts, git_version_used, module) - if depth is not None and git_version_used < LooseVersion('1.9.1'): + if depth is not None and git_version_used is not None and git_version_used < LooseVersion('1.9.1'): module.warn("git version is too old to fully support the depth argument. Falling back to full checkouts.") depth = None