mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
aa88d68ebc
I had been following the documentation examples, and specifiying multiple packages on one line. The right way to do it is with YAML list syntax.
318 lines
9 KiB
YAML
318 lines
9 KiB
YAML
---
|
|
##
|
|
## pkgng - example - state=present for single package
|
|
##
|
|
- name: Verify package sentinel file is not present
|
|
stat:
|
|
path: '{{ pkgng_test_pkg_sentinelfile_path }}'
|
|
get_attributes: no
|
|
get_checksum: no
|
|
get_mime: no
|
|
register: pkgng_example1_stat_before
|
|
|
|
- name: Install package
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
register: pkgng_example1
|
|
|
|
- name: Remove package (checkmode)
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
state: absent
|
|
check_mode: yes
|
|
register: pkgng_example1_checkmode
|
|
|
|
- name: Install package (idempotent, cached)
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
cached: yes
|
|
register: pkgng_example1_idempotent_cached
|
|
|
|
- name: Verify package sentinel file is present
|
|
stat:
|
|
path: '{{ pkgng_test_pkg_sentinelfile_path }}'
|
|
get_attributes: no
|
|
get_checksum: no
|
|
get_mime: no
|
|
register: pkgng_example1_stat_after
|
|
|
|
- name: Ensure pkgng installs package correctly
|
|
assert:
|
|
that:
|
|
- not pkgng_example1_stat_before.stat.exists
|
|
- pkgng_example1.changed
|
|
- pkgng_example1_checkmode.changed
|
|
- not pkgng_example1_idempotent_cached.changed
|
|
- not pkgng_example1_idempotent_cached.stdout is match("Updating \w+ repository catalogue\.\.\.")
|
|
- pkgng_example1_stat_after.stat.exists
|
|
- pkgng_example1_stat_after.stat.executable
|
|
|
|
##
|
|
## pkgng - example - state=latest for already up-to-date package
|
|
##
|
|
- name: Upgrade package (idempotent)
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
state: latest
|
|
register: pkgng_example2
|
|
|
|
- name: Ensure pkgng does not upgrade up-to-date package
|
|
assert:
|
|
that:
|
|
- not pkgng_example2.changed
|
|
|
|
##
|
|
## pkgng - example - state=absent for single package
|
|
##
|
|
- name: Verify package sentinel file is present
|
|
stat:
|
|
path: '{{ pkgng_test_pkg_sentinelfile_path }}'
|
|
get_attributes: no
|
|
get_checksum: no
|
|
get_mime: no
|
|
register: pkgng_example3_stat_before
|
|
|
|
- name: Install package (checkmode)
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
check_mode: yes
|
|
register: pkgng_example3_checkmode
|
|
|
|
- name: Remove package
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
state: absent
|
|
register: pkgng_example3
|
|
|
|
- name: Remove package (idempotent)
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
state: absent
|
|
register: pkgng_example3_idempotent
|
|
|
|
- name: Verify package sentinel file is not present
|
|
stat:
|
|
path: '{{ pkgng_test_pkg_sentinelfile_path }}'
|
|
get_attributes: no
|
|
get_checksum: no
|
|
get_mime: no
|
|
register: pkgng_example3_stat_after
|
|
|
|
- name: Ensure pkgng installs package correctly
|
|
assert:
|
|
that:
|
|
- pkgng_example3_stat_before.stat.exists
|
|
- pkgng_example3_stat_before.stat.executable
|
|
- not pkgng_example3_checkmode.changed
|
|
- pkgng_example3.changed
|
|
- not pkgng_example3_idempotent.changed
|
|
- not pkgng_example3_stat_after.stat.exists
|
|
|
|
##
|
|
## pkgng - example - state=latest for out-of-date package
|
|
##
|
|
- name: Install intentionally out-of-date package and upgrade it
|
|
#
|
|
# NOTE: The out-of-date package provided is a minimal,
|
|
# no-contents test package that declares {{ pkgng_test_pkg_name }} with
|
|
# a version of 0, so it should always be upgraded.
|
|
#
|
|
# This test might fail at some point in the
|
|
# future if the FreeBSD package format receives
|
|
# breaking changes that prevent pkg from installing
|
|
# older package formats.
|
|
#
|
|
block:
|
|
- name: Create out-of-date test package
|
|
import_tasks: create-outofdate-pkg.yml
|
|
|
|
- name: Install out-of-date test package
|
|
command: 'pkg add {{ pkgng_test_outofdate_pkg_path }}'
|
|
register: pkgng_example4_prepare
|
|
|
|
- name: Check for any available package upgrades (checkmode)
|
|
pkgng:
|
|
name: '*'
|
|
state: latest
|
|
check_mode: yes
|
|
register: pkgng_example4_wildcard_checkmode
|
|
|
|
- name: Check for available package upgrade (checkmode)
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
state: latest
|
|
check_mode: yes
|
|
register: pkgng_example4_checkmode
|
|
|
|
- name: Upgrade out-of-date package
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
state: latest
|
|
register: pkgng_example4
|
|
|
|
- name: Upgrade out-of-date package (idempotent)
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
state: latest
|
|
register: pkgng_example4_idempotent
|
|
|
|
- name: Remove test out-of-date package
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
state: absent
|
|
|
|
- name: Ensure pkgng upgrades package correctly
|
|
assert:
|
|
that:
|
|
- not pkgng_example4_prepare.failed
|
|
- pkgng_example4_wildcard_checkmode.changed
|
|
- pkgng_example4_checkmode.changed
|
|
- pkgng_example4.changed
|
|
- not pkgng_example4_idempotent.changed
|
|
|
|
##
|
|
## pkgng - example - Install multiple packages in one command
|
|
##
|
|
- name: Remove test package (checkmode)
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
state: absent
|
|
check_mode: yes
|
|
register: pkgng_example5_prepare
|
|
|
|
- name: Install three packages
|
|
pkgng:
|
|
name:
|
|
- '{{ pkgng_test_pkg_name }}'
|
|
- fish
|
|
- busybox
|
|
register: pkgng_example5
|
|
|
|
- name: Remove three packages
|
|
pkgng:
|
|
name:
|
|
- '{{ pkgng_test_pkg_name }}'
|
|
- fish
|
|
- busybox
|
|
state: absent
|
|
register: pkgng_example5_cleanup
|
|
|
|
- name: Ensure pkgng installs multiple packages with one command
|
|
assert:
|
|
that:
|
|
- not pkgng_example5_prepare.changed
|
|
- pkgng_example5.changed
|
|
- "'Number of packages to be installed: 3' is in(pkgng_example5.stdout_lines)"
|
|
- "(pkgng_example5.stdout | regex_findall('^Number of packages to be', multiline=True) | count) == 1"
|
|
- pkgng_example5_cleanup.changed
|
|
|
|
##
|
|
## pkgng - example - state=latest multiple packages, some already installed
|
|
##
|
|
- name: Remove test package (checkmode)
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
state: absent
|
|
check_mode: yes
|
|
register: pkgng_example6_check
|
|
|
|
- name: Create out-of-date test package
|
|
import_tasks: create-outofdate-pkg.yml
|
|
|
|
- name: Install out-of-date test package
|
|
command: 'pkg add {{ pkgng_test_outofdate_pkg_path }}'
|
|
register: pkgng_example6_prepare
|
|
|
|
- name: Upgrade and/or install two packages
|
|
pkgng:
|
|
name:
|
|
- '{{ pkgng_test_pkg_name }}'
|
|
- fish
|
|
state: latest
|
|
register: pkgng_example6
|
|
|
|
- name: Remove two packages
|
|
pkgng:
|
|
name:
|
|
- '{{ pkgng_test_pkg_name }}'
|
|
- fish
|
|
state: absent
|
|
register: pkgng_example6_cleanup
|
|
|
|
- name: Ensure pkgng installs multiple packages with one command
|
|
assert:
|
|
that:
|
|
- not pkgng_example6_check.changed
|
|
- not pkgng_example6_prepare.failed
|
|
- pkgng_example6.changed
|
|
- "'Number of packages to be installed: 1' is in(pkgng_example6.stdout_lines)"
|
|
- "'Number of packages to be upgraded: 1' is in(pkgng_example6.stdout_lines)"
|
|
# Checking that "will be affected" occurs twice in the output ensures
|
|
# that the module runs two separate commands for install and upgrade,
|
|
# as the pkg command only outputs the string once per invocation.
|
|
- "(pkgng_example6.stdout | regex_findall('will be affected', multiline=True) | count) == 2"
|
|
- pkgng_example6_cleanup.changed
|
|
|
|
##
|
|
## pkgng - example - Install single package in jail
|
|
##
|
|
- name: Test within jail
|
|
#
|
|
# NOTE: FreeBSD 12.0 test runner receives a "connection reset by peer" after ~20% downloaded so we are
|
|
# only running this on 12.1 or higher
|
|
#
|
|
when: ansible_distribution_version is version('12.01', '>=')
|
|
block:
|
|
- name: Setup testjail
|
|
include: setup-testjail.yml
|
|
|
|
- name: Verify package sentinel file is not present
|
|
stat:
|
|
path: '/usr/jails/testjail{{ pkgng_test_pkg_sentinelfile_path }}'
|
|
get_attributes: no
|
|
get_checksum: no
|
|
get_mime: no
|
|
register: pkgng_jail_example1_stat_before
|
|
|
|
- name: Install package in jail
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
jail: testjail
|
|
register: pkgng_jail_example1
|
|
|
|
- name: Remove package (checkmode)
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
state: absent
|
|
jail: testjail
|
|
check_mode: yes
|
|
register: pkgng_jail_example1_checkmode
|
|
|
|
- name: Install package (idempotent)
|
|
pkgng:
|
|
name: '{{ pkgng_test_pkg_name }}'
|
|
jail: testjail
|
|
register: pkgng_jail_example1_idempotent
|
|
|
|
- name: Verify package sentinel file is present
|
|
stat:
|
|
path: '/usr/jails/testjail{{ pkgng_test_pkg_sentinelfile_path }}'
|
|
get_attributes: no
|
|
get_checksum: no
|
|
get_mime: no
|
|
register: pkgng_jail_example1_stat_after
|
|
|
|
- name: Ensure pkgng installs package correctly
|
|
assert:
|
|
that:
|
|
- not pkgng_jail_example1_stat_before.stat.exists
|
|
- pkgng_jail_example1.changed
|
|
- pkgng_jail_example1_checkmode.changed
|
|
- not pkgng_jail_example1_idempotent.changed
|
|
- pkgng_jail_example1_stat_after.stat.exists
|
|
- pkgng_jail_example1_stat_after.stat.executable
|
|
always:
|
|
- name: Stop and remove testjail
|
|
failed_when: false
|
|
changed_when: false
|
|
command: "ezjail-admin delete -wf testjail"
|