User: Raise an error when force is used to delete group

On platforms like Alpine and BusyBox, group delete operation
with force is not applicable. Raise an error notifying the
user about the same.

Fixes: #85565

Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
pull/85610/head
Abhijeet Kasurde 5 months ago
parent 90f62f3fdf
commit 371b7f2b6a

@ -0,0 +1,3 @@
---
bugfixes:
- user - raise an error if force=true is used while deleting the group on Alpine and BusyBox (https://github.com/ansible/ansible/issues/85565).

@ -38,6 +38,7 @@ options:
description:
- Whether to delete a group even if it is the primary group of a user.
- Only applicable on platforms which implement a C(--force) flag on the group deletion command.
- Not applicable on BusyBox and Alpine Linux.
type: bool
default: false
version_added: "2.15"
@ -651,6 +652,9 @@ class BusyBoxGroup(Group):
return self.execute_command(cmd)
def group_del(self):
if self.module.params['force']:
self.module.fail_json(msg='force is not a valid option for this platform.')
cmd = [self.module.get_bin_path('delgroup', True), self.name]
return self.execute_command(cmd)

@ -388,6 +388,35 @@
state: absent
when: ansible_distribution not in ["MacOSX", "Alpine", "FreeBSD"]
# https://github.com/ansible/ansible/issues/85565
- block:
- name: Create a group
group:
name: groupdeltest
state: present
- name: Use force to delete the group
group:
name: groupdeltest
state: absent
force: true
ignore_errors: true
register: force_delete
- name: assert an error occurred while deleting the group with force=true
assert:
that:
- force_delete is failed
- "'force is not a valid option' in force_delete.msg"
always:
- name: Cleanup group
group:
name: groupdeltest
state: absent
when: ansible_distribution in ["Alpine"]
# create system group
- name: remove group

Loading…
Cancel
Save