diff --git a/changelogs/fragments/alpine_group_force.yml b/changelogs/fragments/alpine_group_force.yml new file mode 100644 index 00000000000..3f8a5f00902 --- /dev/null +++ b/changelogs/fragments/alpine_group_force.yml @@ -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). diff --git a/lib/ansible/modules/group.py b/lib/ansible/modules/group.py index a31b9f8c73a..27531380e24 100644 --- a/lib/ansible/modules/group.py +++ b/lib/ansible/modules/group.py @@ -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) diff --git a/test/integration/targets/group/tasks/tests.yml b/test/integration/targets/group/tasks/tests.yml index c4f90be5de7..8f140b47acb 100644 --- a/test/integration/targets/group/tasks/tests.yml +++ b/test/integration/targets/group/tasks/tests.yml @@ -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