diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py index e096250d7a7..ca22b1b9bdc 100644 --- a/lib/ansible/modules/system/user.py +++ b/lib/ansible/modules/system/user.py @@ -2901,7 +2901,7 @@ def main(): # that do not exist. path_needs_parents = False if user.home: - parent = os.path.basename(user.home) + parent = os.path.dirname(user.home) if not os.path.isdir(parent): path_needs_parents = True diff --git a/test/integration/targets/user/tasks/main.yml b/test/integration/targets/user/tasks/main.yml index 5563fe187a0..8459f2b1681 100644 --- a/test/integration/targets/user/tasks/main.yml +++ b/test/integration/targets/user/tasks/main.yml @@ -197,6 +197,22 @@ state: absent +# https://github.com/ansible/ansible/issues/60307 +# Make sure we can create a user when the home directory is missing +- name: Create user with home path that does not exist + user: + name: ansibulluser3 + state: present + home: "{{ user_home_prefix[ansible_facts.system] }}/nosuchdir" + createhome: no + +- name: Cleanup test account + user: + name: ansibulluser3 + state: absent + remove: yes + + ## user check - name: run existing user check tests