Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible-pull git module fails when HOME is not set #72321

Open
aschwanb opened this issue Oct 23, 2020 · 5 comments · May be fixed by #82173
Open

ansible-pull git module fails when HOME is not set #72321

aschwanb opened this issue Oct 23, 2020 · 5 comments · May be fixed by #82173
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. easyfix This issue is considered easy to fix by aspiring contributors. has_pr This issue has an associated PR. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation python3 source_control Source-control category support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@aschwanb
Copy link

SUMMARY

ansible-pull git module fails when HOME is not set. It will produce the error shown in ACTUAL RESULTS when eg. run as a LaunchDaemon on macOS. But will perform fine when run as a LaunchDaemon when explicitly setting HOME to eg "/var/root"

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible/modules/git.py

ANSIBLE VERSION

ansible==2.10.1

CONFIGURATION
OS / ENVIRONMENT

macOS 10.15.7

STEPS TO REPRODUCE

ansible-pull will run fine when executed using the command line but will fail as a LaunchDaemon.

EXPECTED RESULTS

ansible-pull should deliver the same results no matter how it is started.

ACTUAL RESULTS
"module_stderr": "Traceback (most recent call last):
  File \"/var/root/.ansible/tmp/ansible-tmp-1603351341.240792-3548-191494314212665/AnsiballZ_git.py\", line 102, in <module>
    _ansiballz_main()
  File \"/var/root/.ansible/tmp/ansible-tmp-1603351341.240792-3548-191494314212665/AnsiballZ_git.py\", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File \"/var/root/.ansible/tmp/ansible-tmp-1603351341.240792-3548-191494314212665/AnsiballZ_git.py\", line 40, in invoke_module
    runpy.run_module(mod_name='ansible.modules.git', init_globals=None, run_name='__main__', alter_sys=True)
  File \"somepath/Python.framework/Versions/3.8/lib/python3.8/runpy.py\", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File \"somepath/Python.framework/Versions/3.8/lib/python3.8/runpy.py\", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File \"somepath/Python.framework/Versions/3.8/lib/python3.8/runpy.py\", line 87, in _run_code
    exec(code, run_globals)
  File \"/tmp/ansible_git_payload_k6elftyg/ansible_git_payload.zip/ansible/modules/git.py\", line 1277, in <module>
  File \"/tmp/ansible_git_payload_k6elftyg/ansible_git_payload.zip/ansible/modules/git.py\", line 1159, in main
  File \"somepath/Python.framework/Versions/3.8/lib/python3.8/distutils/version.py\", line 64, in __gt__
    c = self._cmp(other)
  File \"somepath/Python.framework/Versions/3.8/lib/python3.8/distutils/version.py\", line 335, in _cmp
    if self.version == other.version:
AttributeError: 'NoneType' object has no attribute 'version'
"
@ansibot
Copy link
Contributor

ansibot commented Oct 23, 2020

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 source_control Source-control category support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback. labels Oct 23, 2020
@sivel
Copy link
Member

sivel commented Oct 26, 2020

This indicates that running git --version is failing, and git_version is returning None. I'm not sure so much why $HOME would affect it, but we can probably guard against the traceback with something like:

diff --git a/lib/ansible/modules/git.py b/lib/ansible/modules/git.py
index b47e94517b..36c3edacf4 100644
--- a/lib/ansible/modules/git.py
+++ b/lib/ansible/modules/git.py
@@ -1156,7 +1156,7 @@ def main():
 
     git_version_used = git_version(git_path, module)
 
-    if depth is not None and git_version_used < LooseVersion('1.9.1'):
+    if depth is not None and git_version_used and git_version_used < LooseVersion('1.9.1'):
         result['warnings'].append("Your git version is too old to fully support the depth argument. Falling back to full checkouts.")
         depth = None
 

@samdoran samdoran changed the title ansible-pull git module failes when HOME is not set ansible-pull git module fails when HOME is not set Oct 27, 2020
@relrod relrod added needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Oct 27, 2020
@eqrx eqrx self-assigned this Feb 5, 2021
@eqrx
Copy link
Contributor

eqrx commented Feb 11, 2021

I can't reproduce it on Arch Linux. ansible-pull will run fine when HOME is not set (with stable2.10 and devel). Maybe a mac user could take a look.

@eqrx eqrx removed their assignment Feb 11, 2021
@marcoslhc
Copy link

This happens to me trying to connect to a mac book pro via ssh. OS: Big Sur 11.2.3

@Shrews
Copy link
Contributor

Shrews commented Jun 2, 2021

Unable to reproduce this on OSX 11.4. Local git is 2.30.1.

@sivel sivel added easyfix This issue is considered easy to fix by aspiring contributors. and removed needs_verified This issue needs to be verified/reproduced by maintainer labels Feb 7, 2022
@Akasurde Akasurde linked a pull request Nov 8, 2023 that will close this issue
Akasurde added a commit to Akasurde/ansible that referenced this issue Nov 8, 2023
Before usage check if the git version is populated or not.

Fixes: ansible#72321

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
@ansibot ansibot added the has_pr This issue has an associated PR. label Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. easyfix This issue is considered easy to fix by aspiring contributors. has_pr This issue has an associated PR. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation python3 source_control Source-control category support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants