From c71622b31a52c44f171a4bb9da1331939ad7aa60 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Mon, 12 Aug 2019 17:37:45 +0300 Subject: [PATCH] user: createhome=no home=/no/such/dir (#60310) Fixes #60307. This bug was introduced in commit d2edf1d43531f938ccbdef79c927141ba193b96d ("User - Create parent directories if they do not exist in the specified home path (#51043)") and did not make it into any releases. --- lib/ansible/modules/system/user.py | 2 +- test/integration/targets/user/tasks/main.yml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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