diff options
author | Strahinja Kustudic <kustodian@gmail.com> | 2019-01-14 22:01:26 +0100 |
---|---|---|
committer | ansibot <ansibot@users.noreply.github.com> | 2019-01-14 16:01:26 -0500 |
commit | eb8294e6d98b0ab7db587be3c8e99a51da6e245d (patch) | |
tree | 39091985ad5d26341ab2a15b6f0550ac50214dbb /test/integration/targets/user | |
parent | 37960ccc87fb3711893d986e6d512920e095044f (diff) | |
download | ansible-eb8294e6d98b0ab7db587be3c8e99a51da6e245d.tar.gz |
Fix create home dir fallback (#49262)
When a user home dir is not created with `useradd`, the home dir will now
be created with umask from /etc/login.defs. Also fixed a bug in which
after a local user is deleted, and the same user exists in the central
user management system, the module would create that user's home.
Diffstat (limited to 'test/integration/targets/user')
-rw-r--r-- | test/integration/targets/user/tasks/main.yml | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/integration/targets/user/tasks/main.yml b/test/integration/targets/user/tasks/main.yml index c9c4fb0dd6..bdaad16bf5 100644 --- a/test/integration/targets/user/tasks/main.yml +++ b/test/integration/targets/user/tasks/main.yml @@ -229,6 +229,62 @@ - '"ansibulluser" not in user_names2.stdout_lines' +## create user without home and test fallback home dir create + +- block: + - name: create the user + user: + name: ansibulluser + + - name: delete the user and home dir + user: + name: ansibulluser + state: absent + force: true + remove: true + + - name: create the user without home + user: + name: ansibulluser + create_home: no + + - name: create the user home dir + user: + name: ansibulluser + register: user_create_home_fallback + + - name: stat home dir + stat: + path: '{{ user_create_home_fallback.home }}' + register: user_create_home_fallback_dir + + - name: read UMASK from /etc/login.defs and return mode + shell: | + import re + import os + try: + for line in open('/etc/login.defs').readlines(): + m = re.match(r'^UMASK\s+(\d+)$', line) + if m: + umask = int(m.group(1), 8) + except: + umask = os.umask(0) + mode = oct(0o777 & ~umask) + print(str(mode).replace('o', '')) + args: + executable: python + register: user_login_defs_umask + + - name: validate that user home dir is created + assert: + that: + - user_create_home_fallback is changed + - user_create_home_fallback_dir.stat.exists + - user_create_home_fallback_dir.stat.isdir + - user_create_home_fallback_dir.stat.pw_name == 'ansibulluser' + - user_create_home_fallback_dir.stat.mode == user_login_defs_umask.stdout + when: ansible_facts.system != 'Darwin' + - block: - name: create non-system user on macOS to test the shell is set to /bin/bash user: |