Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport/2.9/62766 package_facts: check 'vital' and 'automated' values ('pkg' manager) #62825

Merged
merged 1 commit into from Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,2 @@
bugfixes:
- "package_facts - fix value of ``vital`` attribute which is returned when ``pkg`` manager is used"
4 changes: 2 additions & 2 deletions lib/ansible/modules/packaging/os/package_facts.py
Expand Up @@ -241,7 +241,7 @@ def get_package_details(self, package):
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]
Expand All @@ -258,7 +258,7 @@ def get_package_details(self, package):
pkg['revision'] = '0'

if 'vital' in pkg:
pkg['vital'] = bool(pkg['vital'])
pkg['vital'] = bool(int(pkg['vital']))

return pkg

Expand Down
1 change: 0 additions & 1 deletion test/integration/targets/package_facts/aliases
@@ -1,3 +1,2 @@
shippable/posix/group3
skip/freebsd
skip/osx
40 changes: 40 additions & 0 deletions test/integration/targets/package_facts/tasks/main.yml
Expand Up @@ -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"