mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-08 14:20:04 -07:00
snap_alias - new module (#3642)
* snap_alias - manage snap aliases * removed extraneous import * executing the module, the new way * added link and bot entry * scaffolding from snap * completed module + integration tests * fixed sanity checks * Update plugins/modules/packaging/os/snap_alias.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/packaging/os/snap_alias.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/packaging/os/snap_alias.py Co-authored-by: Felix Fontein <felix@fontein.de> * removed extraneous task from test * added seealso, removed unused import * added check_mode + plus check_mode and idempotency tests * Update plugins/modules/packaging/os/snap_alias.py Co-authored-by: Felix Fontein <felix@fontein.de> * Improved RETURN description. Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
b429c520f5
commit
bd96616e6f
15 changed files with 407 additions and 0 deletions
6
tests/integration/targets/snap_alias/aliases
Normal file
6
tests/integration/targets/snap_alias/aliases
Normal file
|
@ -0,0 +1,6 @@
|
|||
shippable/posix/group1
|
||||
skip/aix
|
||||
skip/freebsd
|
||||
skip/osx
|
||||
skip/macos
|
||||
skip/docker
|
4
tests/integration/targets/snap_alias/defaults/main.yml
Normal file
4
tests/integration/targets/snap_alias/defaults/main.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
has_snap: false
|
||||
|
||||
snap_packages:
|
||||
- snapd
|
5
tests/integration/targets/snap_alias/handlers/main.yml
Normal file
5
tests/integration/targets/snap_alias/handlers/main.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
- name: Remove snapd
|
||||
package:
|
||||
name: "{{ snap_packages }}"
|
||||
state: absent
|
3
tests/integration/targets/snap_alias/meta/main.yml
Normal file
3
tests/integration/targets/snap_alias/meta/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
dependencies:
|
||||
- setup_pkg_mgr
|
||||
- setup_epel
|
1
tests/integration/targets/snap_alias/tasks/Debian.yml
Symbolic link
1
tests/integration/targets/snap_alias/tasks/Debian.yml
Symbolic link
|
@ -0,0 +1 @@
|
|||
default.yml
|
1
tests/integration/targets/snap_alias/tasks/Fedora.yml
Symbolic link
1
tests/integration/targets/snap_alias/tasks/Fedora.yml
Symbolic link
|
@ -0,0 +1 @@
|
|||
default.yml
|
1
tests/integration/targets/snap_alias/tasks/RedHat.yml
Symbolic link
1
tests/integration/targets/snap_alias/tasks/RedHat.yml
Symbolic link
|
@ -0,0 +1 @@
|
|||
default.yml
|
21
tests/integration/targets/snap_alias/tasks/default.yml
Normal file
21
tests/integration/targets/snap_alias/tasks/default.yml
Normal file
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
- 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: Create link /snap
|
||||
file:
|
||||
src: /var/lib/snapd/snap
|
||||
dest: /snap
|
||||
state: link
|
||||
|
||||
- name: Inform that snap is installed
|
||||
set_fact:
|
||||
has_snap: true
|
22
tests/integration/targets/snap_alias/tasks/main.yml
Normal file
22
tests/integration/targets/snap_alias/tasks/main.yml
Normal file
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
- 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"
|
||||
|
||||
- name: Test
|
||||
include_tasks: test.yml
|
||||
when: has_snap
|
2
tests/integration/targets/snap_alias/tasks/nothing.yml
Normal file
2
tests/integration/targets/snap_alias/tasks/nothing.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
# Do nothing
|
155
tests/integration/targets/snap_alias/tasks/test.yml
Normal file
155
tests/integration/targets/snap_alias/tasks/test.yml
Normal file
|
@ -0,0 +1,155 @@
|
|||
---
|
||||
- name: Ensure snap 'hello-world' is not installed
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: absent
|
||||
|
||||
- name: Ensure snap 'hello-world' is installed fresh
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
|
||||
################################################################################
|
||||
|
||||
- name: Create snap alias (check mode)
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
alias: hw
|
||||
check_mode: true
|
||||
register: alias_single_0
|
||||
|
||||
- name: Create snap alias
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
alias: hw
|
||||
register: alias_single_1
|
||||
|
||||
- name: Create snap alias (check mode idempotent)
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
alias: hw
|
||||
check_mode: true
|
||||
register: alias_single_2
|
||||
|
||||
- name: Create snap alias (idempotent)
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
alias: hw
|
||||
register: alias_single_3
|
||||
|
||||
- name: assert single alias
|
||||
assert:
|
||||
that:
|
||||
- alias_single_0 is changed
|
||||
- alias_single_1 is changed
|
||||
- alias_single_2 is not changed
|
||||
- alias_single_3 is not changed
|
||||
- 'alias_single_1.snap_aliases["hello-world"] == ["hw"]'
|
||||
- 'alias_single_3.snap_aliases["hello-world"] == ["hw"]'
|
||||
|
||||
- name: Create multiple aliases (check mode)
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
aliases: [hw, hw2, hw3]
|
||||
check_mode: true
|
||||
register: alias_multi_0
|
||||
|
||||
- name: Create multiple aliases
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
aliases: [hw, hw2, hw3]
|
||||
register: alias_multi_1
|
||||
|
||||
- name: Create multiple aliases (check mode idempotent)
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
aliases: [hw, hw2, hw3]
|
||||
check_mode: true
|
||||
register: alias_multi_2
|
||||
|
||||
- name: Create multiple aliases (idempotent)
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
aliases: [hw, hw2, hw3]
|
||||
register: alias_multi_3
|
||||
|
||||
- name: assert multi alias
|
||||
assert:
|
||||
that:
|
||||
- alias_multi_0 is changed
|
||||
- alias_multi_1 is changed
|
||||
- alias_multi_2 is not changed
|
||||
- alias_multi_3 is not changed
|
||||
- 'alias_multi_1.snap_aliases["hello-world"] == ["hw", "hw2", "hw3"]'
|
||||
- 'alias_multi_3.snap_aliases["hello-world"] == ["hw", "hw2", "hw3"]'
|
||||
|
||||
- name: Remove one specific alias (check mode)
|
||||
community.general.snap_alias:
|
||||
alias: hw
|
||||
state: absent
|
||||
check_mode: true
|
||||
register: alias_remove_0
|
||||
|
||||
- name: Remove one specific alias
|
||||
community.general.snap_alias:
|
||||
alias: hw
|
||||
state: absent
|
||||
register: alias_remove_1
|
||||
|
||||
- name: Remove one specific alias (check mode idempotent)
|
||||
community.general.snap_alias:
|
||||
alias: hw
|
||||
state: absent
|
||||
check_mode: true
|
||||
register: alias_remove_2
|
||||
|
||||
- name: Remove one specific alias (idempotent)
|
||||
community.general.snap_alias:
|
||||
alias: hw
|
||||
state: absent
|
||||
register: alias_remove_3
|
||||
|
||||
- name: assert remove alias
|
||||
assert:
|
||||
that:
|
||||
- alias_remove_0 is changed
|
||||
- alias_remove_1 is changed
|
||||
- alias_remove_2 is not changed
|
||||
- alias_remove_3 is not changed
|
||||
- 'alias_remove_1.snap_aliases["hello-world"] == ["hw2", "hw3"]'
|
||||
- 'alias_remove_3.snap_aliases["hello-world"] == ["hw2", "hw3"]'
|
||||
|
||||
- name: Remove all aliases for snap (check mode)
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
state: absent
|
||||
check_mode: true
|
||||
register: alias_remove_all_0
|
||||
|
||||
- name: Remove all aliases for snap
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
state: absent
|
||||
register: alias_remove_all_1
|
||||
|
||||
- name: Remove all aliases for snap (check mode idempotent)
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
state: absent
|
||||
check_mode: true
|
||||
register: alias_remove_all_2
|
||||
|
||||
- name: Remove all aliases for snap (idempotent)
|
||||
community.general.snap_alias:
|
||||
name: hello-world
|
||||
state: absent
|
||||
register: alias_remove_all_3
|
||||
|
||||
- name: assert remove_all alias
|
||||
assert:
|
||||
that:
|
||||
- alias_remove_all_0 is changed
|
||||
- alias_remove_all_1 is changed
|
||||
- alias_remove_all_2 is not changed
|
||||
- alias_remove_all_3 is not changed
|
||||
- 'alias_remove_all_1.snap_aliases["hello-world"] == []'
|
||||
- 'alias_remove_all_3.snap_aliases["hello-world"] == []'
|
Loading…
Add table
Add a link
Reference in a new issue