diff options
author | Pilou <pierre-louis.bonicoli@libregerbil.fr> | 2019-09-24 10:03:56 +0200 |
---|---|---|
committer | René Moser <mail@renemoser.net> | 2019-09-24 10:03:56 +0200 |
commit | 278398555d08b37a2a8b4f454e8add7238595a2d (patch) | |
tree | 3ee7dba2f0f0537b8a8d382357edd777235b56c6 | |
parent | Fix whitespace issue in filter (#62768) (diff) | |
download | ansible-278398555d08b37a2a8b4f454e8add7238595a2d.tar.xz ansible-278398555d08b37a2a8b4f454e8add7238595a2d.zip |
package_facts: check 'vital' and 'automated' values ('pkg' manager) (#62766)
4 files changed, 44 insertions, 3 deletions
diff --git a/changelogs/fragments/62766-package_facts-pkg-manager-fix-vital-value.yml b/changelogs/fragments/62766-package_facts-pkg-manager-fix-vital-value.yml new file mode 100644 index 0000000000..aef33d4490 --- /dev/null +++ b/changelogs/fragments/62766-package_facts-pkg-manager-fix-vital-value.yml @@ -0,0 +1,2 @@ +bugfixes: + - "package_facts - fix value of ``vital`` attribute which is returned when ``pkg`` manager is used" diff --git a/lib/ansible/modules/packaging/os/package_facts.py b/lib/ansible/modules/packaging/os/package_facts.py index ae08154eac..fc1ebc812e 100644 --- a/lib/ansible/modules/packaging/os/package_facts.py +++ b/lib/ansible/modules/packaging/os/package_facts.py @@ -241,7 +241,7 @@ class PKG(CLIMgr): pass if 'automatic' in pkg: - pkg['automatic'] = bool(pkg['automatic']) + pkg['automatic'] = bool(int(pkg['automatic'])) if 'category' in pkg: pkg['category'] = pkg['category'].split('/', 1)[0] @@ -258,7 +258,7 @@ class PKG(CLIMgr): pkg['revision'] = '0' if 'vital' in pkg: - pkg['vital'] = bool(pkg['vital']) + pkg['vital'] = bool(int(pkg['vital'])) return pkg diff --git a/test/integration/targets/package_facts/aliases b/test/integration/targets/package_facts/aliases index 4662751b43..a999931de2 100644 --- a/test/integration/targets/package_facts/aliases +++ b/test/integration/targets/package_facts/aliases @@ -1,3 +1,2 @@ shippable/posix/group3 -skip/freebsd skip/osx diff --git a/test/integration/targets/package_facts/tasks/main.yml b/test/integration/targets/package_facts/tasks/main.yml index 0ca00a42e5..12dfcf0316 100644 --- a/test/integration/targets/package_facts/tasks/main.yml +++ b/test/integration/targets/package_facts/tasks/main.yml @@ -73,3 +73,43 @@ - name: check for ansible_facts.packages exists assert: that: ansible_facts.packages is defined + +- name: Run package_fact tests - FreeBSD + block: + - name: Gather package facts + package_facts: + manager: pkg + + - name: check for ansible_facts.packages exists + assert: + that: ansible_facts.packages is defined + + - name: check there is at least one package not flagged vital nor automatic + command: pkg query -e "%a = 0 && %V = 0" %n + register: not_vital_nor_automatic + failed_when: not not_vital_nor_automatic.stdout + + - vars: + pkg_name: "{{ not_vital_nor_automatic.stdout_lines[0].strip() }}" + block: + - name: check the selected package is not vital + assert: + that: + - 'not ansible_facts.packages[pkg_name][0].vital' + - 'not ansible_facts.packages[pkg_name][0].automatic' + + - name: flag the selected package as vital and automatic + command: 'pkg set --yes -v 1 -A 1 {{ pkg_name }}' + + - name: Gather package facts (again) + package_facts: + + - name: check the selected package is flagged vital and automatic + assert: + that: + - 'ansible_facts.packages[pkg_name][0].vital|bool' + - 'ansible_facts.packages[pkg_name][0].automatic|bool' + always: + - name: restore previous flags for the selected package + command: 'pkg set --yes -v 0 -A 0 {{ pkg_name }}' + when: ansible_os_family == "FreeBSD" |