mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Fix snap module, and module helper behavior on rc != 0 in output (#2912)
* 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 77ca91f502
.
* 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.
This commit is contained in:
parent
a97d82be88
commit
c63dc624b7
13 changed files with 111 additions and 45 deletions
|
@ -3,4 +3,4 @@ skip/aix
|
|||
skip/freebsd
|
||||
skip/osx
|
||||
skip/macos
|
||||
disabled #FIXME 2609
|
||||
skip/docker
|
||||
|
|
4
tests/integration/targets/snap/defaults/main.yml
Normal file
4
tests/integration/targets/snap/defaults/main.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
has_snap: false
|
||||
|
||||
snap_packages:
|
||||
- snapd
|
5
tests/integration/targets/snap/handlers/main.yml
Normal file
5
tests/integration/targets/snap/handlers/main.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
- name: Remove snapd
|
||||
package:
|
||||
name: "{{ snap_packages }}"
|
||||
state: absent
|
3
tests/integration/targets/snap/meta/main.yml
Normal file
3
tests/integration/targets/snap/meta/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
dependencies:
|
||||
- setup_pkg_mgr
|
||||
- setup_epel
|
1
tests/integration/targets/snap/tasks/Debian.yml
Symbolic link
1
tests/integration/targets/snap/tasks/Debian.yml
Symbolic link
|
@ -0,0 +1 @@
|
|||
default.yml
|
1
tests/integration/targets/snap/tasks/Fedora.yml
Symbolic link
1
tests/integration/targets/snap/tasks/Fedora.yml
Symbolic link
|
@ -0,0 +1 @@
|
|||
default.yml
|
1
tests/integration/targets/snap/tasks/RedHat.yml
Symbolic link
1
tests/integration/targets/snap/tasks/RedHat.yml
Symbolic link
|
@ -0,0 +1 @@
|
|||
default.yml
|
15
tests/integration/targets/snap/tasks/default.yml
Normal file
15
tests/integration/targets/snap/tasks/default.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
- name: Install snapd
|
||||
package:
|
||||
name: "{{ snap_packages }}"
|
||||
state: present
|
||||
notify: Remove snapd
|
||||
|
||||
- name: Make sure that snapd is running
|
||||
service:
|
||||
name: snapd
|
||||
state: started
|
||||
|
||||
- name: Inform that snap is installed
|
||||
set_fact:
|
||||
has_snap: true
|
|
@ -4,28 +4,46 @@
|
|||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
- name: install snapd
|
||||
apt:
|
||||
name: snapd
|
||||
state: present
|
||||
register: snapd_install_ubuntu
|
||||
when: ansible_distribution == 'Ubuntu'
|
||||
|
||||
- name: install snapd
|
||||
dnf:
|
||||
name: snapd
|
||||
state: present
|
||||
register: snapd_install_fedora
|
||||
when: ansible_distribution == 'Fedora'
|
||||
- name: Include distribution specific tasks
|
||||
include_tasks: "{{ lookup('first_found', params) }}"
|
||||
vars:
|
||||
params:
|
||||
files:
|
||||
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml"
|
||||
- "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml"
|
||||
- "{{ ansible_facts.distribution }}.yml"
|
||||
- "{{ ansible_facts.os_family }}.yml"
|
||||
- "nothing.yml"
|
||||
paths:
|
||||
- "{{ role_path }}/tasks"
|
||||
|
||||
- block:
|
||||
- name: install package
|
||||
- name: Make sure package is not installed
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: absent
|
||||
|
||||
- name: Install package (check mode)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: present
|
||||
register: install_check
|
||||
check_mode: true
|
||||
|
||||
- name: Install package
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: present
|
||||
register: install
|
||||
|
||||
- name: install package again
|
||||
- name: Install package again (check mode)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: present
|
||||
register: install_again_check
|
||||
check_mode: true
|
||||
|
||||
- name: Install package again
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: present
|
||||
|
@ -35,18 +53,36 @@
|
|||
assert:
|
||||
that:
|
||||
- install is changed
|
||||
- install_check is changed
|
||||
- install_again is not changed
|
||||
- install_again_check is not changed
|
||||
|
||||
- name: check package has been installed correctly
|
||||
- name: Check package has been installed correctly
|
||||
command: hello-world
|
||||
environment:
|
||||
PATH: /var/lib/snapd/snap/bin/
|
||||
|
||||
- name: remove package
|
||||
- name: Remove package (check mode)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: absent
|
||||
register: remove_check
|
||||
check_mode: true
|
||||
|
||||
- name: Remove package
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: absent
|
||||
register: remove
|
||||
|
||||
- name: remove package again
|
||||
- name: Remove package again (check mode)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: absent
|
||||
register: remove_again_check
|
||||
check_mode: true
|
||||
|
||||
- name: Remove package again
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: absent
|
||||
|
@ -56,17 +92,7 @@
|
|||
assert:
|
||||
that:
|
||||
- remove is changed
|
||||
- remove_check is changed
|
||||
- remove_again is not changed
|
||||
when: ansible_distribution in ['Ubuntu','Fedora']
|
||||
|
||||
- name: Remove snapd in case it was not installed
|
||||
apt:
|
||||
name: snapd
|
||||
state: absent
|
||||
when: snapd_install_ubuntu is changed and ansible_distribution == 'Ubuntu'
|
||||
|
||||
- name: Remove snapd in case it was not installed
|
||||
dnf:
|
||||
name: snapd
|
||||
state: absent
|
||||
when: snapd_install_fedora is changed and ansible_distribution == 'Fedora'
|
||||
- remove_again_check is not changed
|
||||
when: has_snap
|
||||
|
|
2
tests/integration/targets/snap/tasks/nothing.yml
Normal file
2
tests/integration/targets/snap/tasks/nothing.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
# Do nothing
|
Loading…
Add table
Add a link
Reference in a new issue