diff --git a/changelogs/fragments/85542-warning-when-using-seuser-on-alpine.yml b/changelogs/fragments/85542-warning-when-using-seuser-on-alpine.yml new file mode 100644 index 00000000000..ef8964fce48 --- /dev/null +++ b/changelogs/fragments/85542-warning-when-using-seuser-on-alpine.yml @@ -0,0 +1,2 @@ +bugfixes: + - user - The seuser parameter will be ignored on Alpine and print warning \ No newline at end of file diff --git a/lib/ansible/modules/user.py b/lib/ansible/modules/user.py index b81258153fd..e78db332a8e 100644 --- a/lib/ansible/modules/user.py +++ b/lib/ansible/modules/user.py @@ -44,6 +44,7 @@ options: seuser: description: - Optionally sets the C(seuser) type C(user_u) on SELinux enabled systems. + - This parameter will be ignored on Alpine and Buildroot. type: str version_added: "2.1" group: @@ -3164,6 +3165,9 @@ class BusyBox(User): cmd.append('-K') cmd.append('UID_MAX=' + str(self.uid_max)) + if self.seuser is not None: + self.module.warn(f"The 'seuser' parameter is not supported on {self.distribution} as it lacks SELinux support and has been ignored.") + cmd.append(self.name) rc, out, err = self.execute_command(cmd) diff --git a/test/integration/targets/user/tasks/main.yml b/test/integration/targets/user/tasks/main.yml index 6a3c84eecd7..21f6c804951 100644 --- a/test/integration/targets/user/tasks/main.yml +++ b/test/integration/targets/user/tasks/main.yml @@ -34,3 +34,6 @@ - ansible_facts.system == 'Linux' - ansible_distribution != 'Alpine' - import_tasks: ssh_keygen.yml +- import_tasks: test_seuser.yml + when: + - ansible_distribution == 'Alpine' diff --git a/test/integration/targets/user/tasks/test_seuser.yml b/test/integration/targets/user/tasks/test_seuser.yml new file mode 100644 index 00000000000..f204e6d177e --- /dev/null +++ b/test/integration/targets/user/tasks/test_seuser.yml @@ -0,0 +1,10 @@ +- name: Try creating user with nonexistent SELinux user + user: + name: badseuser + seuser: nonexistent_u + state: present + register: test_seuser + +- name: there should be warnings + assert: + that: "'warnings' in test_seuser" \ No newline at end of file