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

snap module fails with state absent on snap that is not installed #2835

Closed
1 task done
jkman340 opened this issue Jun 18, 2021 · 6 comments · Fixed by #2912
Closed
1 task done

snap module fails with state absent on snap that is not installed #2835

jkman340 opened this issue Jun 18, 2021 · 6 comments · Fixed by #2912
Labels
bug This issue/PR relates to a bug has_pr module module os packaging plugins plugin (any type) python3

Comments

@jkman340
Copy link

Summary

Using snap module to ensure a snap is not installed on system. Task fails with error "No snap matching 'foo' available."

Issue Type

Bug Report

Component Name

community.general.snap

Ansible Version

ansible 2.10.5
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.0]



### Configuration

```console (paste below)
$ ansible-config dump --only-changed

ANSIBLE_PIPELINING(/etc/ansible/ansible.cfg) = True

OS / Environment

Ubuntu 18.04

Steps to Reproduce

- community.general.snap:
     name: 
       - foo
     state: absent

Expected Results

Module to pass with OK (not changed)

Actual Results

Module fails with error above

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@jkman340
Copy link
Author

Same as this closed issue #1433 but does not work for me. Confirmed snapd is running on remote system.

@quidame
Copy link
Collaborator

quidame commented Jun 19, 2021

!component =plugins/modules/packaging/os/snap.py

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added module module os packaging plugins plugin (any type) labels Jun 19, 2021
@aminvakil
Copy link
Contributor

Taking a quick look at code it seems that it fails here:

self.validate_input_snaps() # if snap doesnt exist, it will be absent by definition

which calls here:
def validate_input_snaps(self):
"""Ensure that all exist."""
for snap_name in self.vars.name:
if not self.snap_exists(snap_name):
raise ModuleHelperException(msg="No snap matching '%s' available." % snap_name)

which checks this:
def snap_exists(self, snap_name):
return 0 == self.run_command(params=[{'state': 'info'}, {'name': [snap_name]}])[0]

I guess it's fine to fail if package does not exist in snap repository, does snap return non-zero if package exists in snap repository but it isn't installed when executing snap info pkg?

@felixfontein
Copy link
Collaborator

Please note that the snap module in the main branch is pretty much different from the one in stable-3, since the backport #2542 hasn't yet been merged. (I accidentally merged the original PR too early; I'm still waiting for someone to test the backport before merging it.)

@felixfontein
Copy link
Collaborator

I think this is also fixed by #2912.

felixfontein added a commit to felixfontein/community.general that referenced this issue Jun 30, 2021
felixfontein added a commit that referenced this issue Jul 1, 2021
* Try some snap fixes.

* Fix logic.

* Try to run tests privileged.

* Prevent failure on rc != 0.

* Fix formatting.

* Revert "Try to run tests privileged."

This reverts commit 77ca91f.

* Try to run tests on RHEL instead.

* Make sure that snapd is running.

* Add changelog fragment.

* str -> to_native.

* Make sure that installed binary is actually found.

* Add check mode tests.

* Mention #2835 in changelog fragment.
patchback bot pushed a commit that referenced this issue Jul 1, 2021
* Try some snap fixes.

* Fix logic.

* Try to run tests privileged.

* Prevent failure on rc != 0.

* Fix formatting.

* Revert "Try to run tests privileged."

This reverts commit 77ca91f.

* Try to run tests on RHEL instead.

* Make sure that snapd is running.

* Add changelog fragment.

* str -> to_native.

* Make sure that installed binary is actually found.

* Add check mode tests.

* Mention #2835 in changelog fragment.

(cherry picked from commit c63dc62)
felixfontein added a commit that referenced this issue Jul 1, 2021
…) (#2915)

* Try some snap fixes.

* Fix logic.

* Try to run tests privileged.

* Prevent failure on rc != 0.

* Fix formatting.

* Revert "Try to run tests privileged."

This reverts commit 77ca91f.

* Try to run tests on RHEL instead.

* Make sure that snapd is running.

* Add changelog fragment.

* str -> to_native.

* Make sure that installed binary is actually found.

* Add check mode tests.

* Mention #2835 in changelog fragment.

(cherry picked from commit c63dc62)

Co-authored-by: Felix Fontein <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr module module os packaging plugins plugin (any type) python3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants