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

offline mode still calling ansible-galaxy #2042

Closed
MarkusTeufelberger opened this issue Mar 24, 2022 · 9 comments · Fixed by #2115
Closed

offline mode still calling ansible-galaxy #2042

MarkusTeufelberger opened this issue Mar 24, 2022 · 9 comments · Fixed by #2115
Assignees
Labels
Milestone

Comments

@MarkusTeufelberger
Copy link
Contributor

Summary

No matter if specified on the command line or in the config file, ansible-lint tries to call ansible-galaxy

Issue Type
  • Bug Report
Ansible and Ansible Lint details
ansible --version
ansible [core 2.12.3]
  config file = /my/custom/path/ansible.cfg
  configured module search path = ['/home/myusername/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /my/custom/path/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.6 (default, Oct  6 2020, 04:02:53) [GCC 5.4.0 20160609]
  jinja version = 2.10
  libyaml = True


ansible-lint --version
WARNING: PATH altered to include /usr/bin
ansible-lint 6.0.2 using ansible 2.12.3
  • ansible installation method: pip
  • ansible-lint installation method: pip
OS / ENVIRONMENT

Ubuntu 18.04 with Python 3.8

STEPS TO REPRODUCE

No matter if called without any config file (the actual one has a .yml ending to make it easier for pre-commit...)

ansible-lint -v --offline
WARNING: PATH altered to include /usr/bin
INFO     Running ansible-galaxy collection install -vr requirements.yml -p /home/myusername/.cache/ansible-compat/26acd4/collections
^C

or with the config file, containing offline: true

ansible-lint -v -c .ansible-lint.yml
WARNING: PATH altered to include /usr/bin
INFO     Running ansible-galaxy collection install -vr requirements.yml -p /home/myusername/.cache/ansible-compat/26acd4/collections
^C

In both cases ansible-lint calls out to ansible-galaxy collection install which is definitely not what it should do. Collections are managed by me and I don't want the linter to change anything on disk. I also want to be very explicit about which collections are installed, the above command will automatically also install (unpinned!) dependencies of collections for example. Lastly, this is the wrong path to install collections to or look for them, as you can see in the output of ansible --version above. Collections are vendored in the folder and this is also specified in the ansible.cfg right there.

Desired Behavior

No calls to ansible-galaxy (and no internet communication at all actually) when specifying --offline.

Actual Behavior

See above, apparently it tries to install collections to some ~/.cache folder that can't be set using the config file of ansible-lint (https://ansible-lint.readthedocs.io/en/latest/configuring/) and that shouldn't happen anyways.

@MarkusTeufelberger MarkusTeufelberger added bug new Triage required labels Mar 24, 2022
@MarkusTeufelberger
Copy link
Contributor Author

Looking a bit further this seems to have been ripped out together with the prerun library. I assume that --offline is a complete no-op in ansible-lint v6 and broken since that major version was released. There don't seem to be tests for that feature.

@MarkusTeufelberger
Copy link
Contributor Author

Even further digging:

The issue seems to be in a different repository alltogether:

https://github.com/ansible/ansible-compat/blob/2140084a6926b6eb911a5ab962e7f0164915620d/src/ansible_compat/runtime.py#L309

(called in

app.runtime.prepare_environment()
)

As soon as a file named requirements.yml exists, ansible-compat will exec any binary on PATHnamed ansible-galaxy, no matter what. I don't see an obvious way how/if the offline option is even propagated that far into the whole system. It doesn't seem to make it into the Runtime class though and I'm also not so sure how to then get it to use the correct path with the already installed collections on disk in there (since isolated = True is being set there).

@ganeshrn ganeshrn removed the new Triage required label Mar 30, 2022
@ganeshrn ganeshrn added this to the 6.0.0 milestone Mar 30, 2022
@dfelton
Copy link

dfelton commented Apr 8, 2022

commenting merely to subscribe this this individual issue.

EDIT: For what it is worth, as this may help others until this is resolved:

My workaround was to merely rename requirements.yml to .requirements.yml. This will prevent ansible-lint from having ansible-galaxy automatically install dependencies. When appropriate, dependencies can still be installed by executing ansible-galaxy install -r .requirements.yml

@MarkusTeufelberger
Copy link
Contributor Author

Apparently this was broken on purpose here: ansible/ansible-compat#37

@nre-ableton
Copy link
Contributor

If that is the case, then I would argue that the --offline argument should be removed altogether, rather than giving users a false impression that it works.

@MarkusTeufelberger
Copy link
Contributor Author

I'd rather see it fixed, it is a non-starter for a linter to access resources on some foreign host upon every single invocation.

@nre-ableton
Copy link
Contributor

Same here, but I have a feeling that the maintainers are not interested in keeping this feature around, sadly.

@MarkusTeufelberger
Copy link
Contributor Author

Well, https://github.com/ansible/ansible-compat is (theoretically?) maintained by IBM/Red Hat, not the Ansible community, even though the license file in there says otherwise? It is a bit confusing which functionality should go where, but all in all this is something that needs to be fixed as it also currently breaks my CI runs if I don't apply workarounds AND it also will cause a lot of completely unnecessary traffic for galaxy. Either I break convention by renaming requirements.yml or I break CI by downloading from a web server (which is not as reliable a service as one might hope by the way....)

@ssbarnea
Copy link
Member

ssbarnea commented May 9, 2022

Offline mode is here to stay, the fact that is does not work well is a bug.

ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue May 10, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue May 10, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue May 10, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue May 10, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue May 10, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue May 10, 2022
@ssbarnea ssbarnea modified the milestones: 6.0.0, 6.2.0 May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants