diff --git a/changelogs/fragments/86243-user-busybox-shell-warn.yml b/changelogs/fragments/86243-user-busybox-shell-warn.yml new file mode 100644 index 00000000000..44501686b16 --- /dev/null +++ b/changelogs/fragments/86243-user-busybox-shell-warn.yml @@ -0,0 +1,2 @@ +bugfixes: + - user - On BusyBox systems, warn when an invalid shell is specified (https://github.com/ansible/ansible/pull/86342) diff --git a/lib/ansible/modules/user.py b/lib/ansible/modules/user.py index 4124538d01d..d9e19a2815c 100644 --- a/lib/ansible/modules/user.py +++ b/lib/ansible/modules/user.py @@ -3133,6 +3133,24 @@ class BusyBox(User): - remove_user() - modify_user() """ + def _validate_shell(self): + if not self.shell: + return + + try: + with open("/etc/shells", "r") as f: + shells = [ + shell + for shell in (line.strip() for line in f) + if shell + and not shell.startswith("#") + ] + except FileNotFoundError: + return + + if self.shell not in shells: + self.module.warn(f"'{self.shell}' is not listed as a valid shell on the remote host.") + def _build_password_string(self, current_password=None): """ Build the appropriate password string based on the current password and @@ -3166,6 +3184,8 @@ class BusyBox(User): def create_user(self): cmd = [self.module.get_bin_path('adduser', True)] + self._validate_shell() + cmd.append('-D') if self.uid is not None: @@ -3275,6 +3295,8 @@ class BusyBox(User): add_cmd_bin = self.module.get_bin_path('adduser', True) remove_cmd_bin = self.module.get_bin_path('delgroup', True) + self._validate_shell() + # Manage group membership if self.groups: groups = self.get_groups_set() or set()