From 315e58b4b9b1ae7f08df89e71e96736705cee859 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 12 Aug 2025 08:28:47 -0700 Subject: [PATCH] Review requests Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/alpine_group_force.yml | 2 +- lib/ansible/modules/group.py | 12 ++++++++++-- test/integration/targets/group/tasks/tests.yml | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/changelogs/fragments/alpine_group_force.yml b/changelogs/fragments/alpine_group_force.yml index 3f8a5f00902..8db20c2d410 100644 --- a/changelogs/fragments/alpine_group_force.yml +++ b/changelogs/fragments/alpine_group_force.yml @@ -1,3 +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). + - user - raise an error if force=true is used while deleting the group on BusyBox based distros (https://github.com/ansible/ansible/issues/85565). diff --git a/lib/ansible/modules/group.py b/lib/ansible/modules/group.py index 27531380e24..ccb99bd79bf 100644 --- a/lib/ansible/modules/group.py +++ b/lib/ansible/modules/group.py @@ -38,7 +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. + - Not applicable on macOS, *BSD and BusyBox based distros. type: bool default: false version_added: "2.15" @@ -401,6 +401,8 @@ class FreeBsdGroup(Group): GROUPFILE = '/etc/group' def group_del(self): + if self.module.params['force']: + self.module.fail_json(msg='The force option is not supported for group deletion on this platform.') cmd = [self.module.get_bin_path('pw', True), 'groupdel', self.name] return self.execute_command(cmd) @@ -477,6 +479,8 @@ class DarwinGroup(Group): return (rc, out, err) def group_del(self): + if self.module.params['force']: + self.module.fail_json(msg='The force option is not supported for group deletion on this platform.') cmd = [self.module.get_bin_path('dseditgroup', True)] cmd += ['-o', 'delete'] cmd += ['-L', self.name] @@ -531,6 +535,8 @@ class OpenBsdGroup(Group): GROUPFILE = '/etc/group' def group_del(self): + if self.module.params['force']: + self.module.fail_json(msg='The force option is not supported for group deletion on this platform.') cmd = [self.module.get_bin_path('groupdel', True), self.name] return self.execute_command(cmd) @@ -583,6 +589,8 @@ class NetBsdGroup(Group): GROUPFILE = '/etc/group' def group_del(self): + if self.module.params['force']: + self.module.fail_json(msg='The force option is not supported for group deletion on this platform.') cmd = [self.module.get_bin_path('groupdel', True), self.name] return self.execute_command(cmd) @@ -653,7 +661,7 @@ class BusyBoxGroup(Group): def group_del(self): if self.module.params['force']: - self.module.fail_json(msg='force is not a valid option for this platform.') + self.module.fail_json(msg='The force option is not supported for group deletion on this platform.') cmd = [self.module.get_bin_path('delgroup', True), self.name] return self.execute_command(cmd) diff --git a/test/integration/targets/group/tasks/tests.yml b/test/integration/targets/group/tasks/tests.yml index 8f140b47acb..29d324217f5 100644 --- a/test/integration/targets/group/tasks/tests.yml +++ b/test/integration/targets/group/tasks/tests.yml @@ -407,7 +407,7 @@ assert: that: - force_delete is failed - - "'force is not a valid option' in force_delete.msg" + - "'The force option is not supported' in force_delete.msg" always: - name: Cleanup group @@ -415,7 +415,7 @@ name: groupdeltest state: absent - when: ansible_distribution in ["Alpine"] + when: ansible_distribution in ["MacOSX", "Alpine", "FreeBSD"] # create system group