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

pacman: Fix removing locally installed packages #4464

Merged
merged 5 commits into from
Apr 13, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/4464-pacman-fix-local-remove.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- pacman - fixed bug where ``absent`` state did not work for locally installed packages (https://github.com/ansible-collections/community.general/pull/4464).
5 changes: 3 additions & 2 deletions plugins/modules/packaging/os/pacman.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,9 @@ def package_list(self):
# Expand group members
for group_member in self.inventory["available_groups"][pkg]:
pkg_list.append(Package(name=group_member, source=group_member))
elif pkg in self.inventory["available_pkgs"]:
# just a regular pkg
elif pkg in self.inventory["available_pkgs"] or pkg in self.inventory["installed_pkgs"]:
# Just a regular pkg, either available in the repositories,
# or locally installed, which we need to know for absent state
pkg_list.append(Package(name=pkg, source=pkg))
else:
# Last resort, call out to pacman to extract the info,
Expand Down
1 change: 1 addition & 0 deletions tests/integration/targets/pacman/aliases
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ skip/freebsd
skip/osx
skip/macos
skip/rhel
needs/root
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
- vars:
package_name: ansible-test-foo
username: ansible-regular-user
block:
- name: Install fakeroot
pacman:
state: present
name:
- fakeroot

- name: Create user
user:
name: '{{ username }}'
home: '/home/{{ username }}'
create_home: true

- name: Create directory
file:
path: '/home/{{ username }}/{{ package_name }}'
state: directory
owner: '{{ username }}'

- name: Create PKGBUILD
copy:
dest: '/home/{{ username }}/{{ package_name }}/PKGBUILD'
content: |
pkgname=('{{ package_name }}')
pkgver=1.0.0
pkgrel=1
pkgdesc="Test removing a local package not in the repositories"
arch=('any')
license=('GPL v3+')
owner: '{{ username }}'

- name: Build package
command:
cmd: su {{ username }} -c "makepkg -srf"
chdir: '/home/{{ username }}/{{ package_name }}'

- name: Install package
pacman:
state: present
name:
- '/home/{{ username }}/{{ package_name }}/{{ package_name }}-1.0.0-1-any.pkg.tar.zst'

- name: Remove package (check mode)
pacman:
state: absent
name:
- '{{ package_name }}'
check_mode: true
register: remove_1

- name: Remove package
pacman:
state: absent
name:
- '{{ package_name }}'
register: remove_2

- name: Remove package (idempotent)
pacman:
state: absent
name:
- '{{ package_name }}'
register: remove_3

- name: Check conditions
assert:
that:
- remove_1 is changed
- remove_2 is changed
- remove_3 is not changed

always:
- name: Remove directory
file:
path: '{{ remote_tmp_dir }}/{{ package_name }}'
state: absent
become: true
1 change: 1 addition & 0 deletions tests/integration/targets/pacman/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
- include: 'package_urls.yml'
- include: 'remove_nosave.yml'
- include: 'update_cache.yml'
- include: 'locally_installed_package.yml'