--- #################################################################### # WARNING: These are designed specifically for Ansible tests # # and should not be used as examples of how to write Ansible roles # #################################################################### - block: - 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 (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 register: install_again - name: Assert package has been installed just once 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 command: hello-world environment: PATH: /var/lib/snapd/snap/bin/ - 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 (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 register: remove_again - name: Assert package has been removed just once assert: that: - remove is changed - remove_check is changed - remove_again is not changed - remove_again_check is not changed - name: Make sure package from classic snap is not installed community.general.snap: name: nvim state: absent - name: Install package from classic snap community.general.snap: name: nvim state: present classic: true register: classic_install # testing classic idempotency - name: Install package from classic snap again community.general.snap: name: nvim state: present classic: true register: classic_install_again - name: Assert package has been installed just once assert: that: - classic_install is changed - classic_install_again is not changed # this is just testing if a package which has been installed # with true classic can be removed without setting classic to true - name: Remove package from classic snap without setting classic to true community.general.snap: name: nvim state: absent register: classic_remove_without_true_classic - name: Remove package from classic snap with setting classic to true community.general.snap: name: nvim state: absent classic: true register: classic_remove_with_true_classic - name: Assert package has been removed without setting classic to true assert: that: - classic_remove_without_true_classic is changed - classic_remove_with_true_classic is not changed when: has_snap