diff options
author | Sam Doran <sdoran@redhat.com> | 2019-03-14 22:16:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-14 22:16:53 -0400 |
commit | 1e595493d92952d168af6cf1bef58d41abcb6a8f (patch) | |
tree | 884e3a11a8cbb5a88267076a4c9bae2d789b3fdb /test/integration/targets/user | |
parent | 43a44e6f3533170557cb971df6b3272e8bb7fa6b (diff) | |
download | ansible-1e595493d92952d168af6cf1bef58d41abcb6a8f.tar.gz |
User module - Check local database when local is specified in the task (#51088)
The output of pw.getpwnam() does not distinbuish between local and remote accounts. It will return a result if an account exists locally or in the directory. When local is set to True in the task parameters, look through the local password database explicitly.
* Ensure luseradd is present for tests
* Add docs and warnings about local mode
Diffstat (limited to 'test/integration/targets/user')
-rw-r--r-- | test/integration/targets/user/tasks/main.yml | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/test/integration/targets/user/tasks/main.yml b/test/integration/targets/user/tasks/main.yml index bc268e2d51..3923c0d79c 100644 --- a/test/integration/targets/user/tasks/main.yml +++ b/test/integration/targets/user/tasks/main.yml @@ -255,7 +255,7 @@ mode = oct(0o777 & ~umask) print(str(mode).replace('o', '')) args: - executable: python + executable: "{{ ansible_facts.python.executable }}" register: user_login_defs_umask - name: validate that user home dir is created @@ -775,3 +775,85 @@ password_lock: no when: ansible_facts['system'] in ['FreeBSD', 'OpenBSD', 'Linux'] + + + ## Check local mode + # Even if we don't have a system that is bound to a directory, it's useful + # to run with local: true to exercise the code path that reads through the local + # user database file. + # https://github.com/ansible/ansible/issues/50947 + +- name: Create /etc/gshadow + file: + path: /etc/gshadow + state: touch + when: ansible_facts.os_family == 'Suse' + tags: + - user_test_local_mode + +- name: Create /etc/libuser.conf + file: + path: /etc/libuser.conf + state: touch + when: + - ansible_facts.distribution == 'Ubuntu' + - ansible_facts.distribution_major_version is version_compare('16', '==') + tags: + - user_test_local_mode + +- name: Ensure luseradd is present + action: "{{ ansible_facts.pkg_mgr }}" + args: + name: libuser + state: present + when: ansible_facts.system in ['Linux'] + tags: + - user_test_local_mode + +- name: Create local_ansibulluser + user: + name: local_ansibulluser + state: present + local: yes + register: local_user_test_1 + tags: + - user_test_local_mode + +- name: Create local_ansibulluser again + user: + name: local_ansibulluser + state: present + local: yes + register: local_user_test_2 + tags: + - user_test_local_mode + +- name: Remove local_ansibulluser + user: + name: local_ansibulluser + state: absent + remove: yes + local: yes + register: local_user_test_3 + tags: + - user_test_local_mode + +- name: Remove local_ansibulluser again + user: + name: local_ansibulluser + state: absent + remove: yes + local: yes + register: local_user_test_4 + tags: + - user_test_local_mode + +- name: Ensure local user accounts were created + assert: + that: + - local_user_test_1 is changed + - local_user_test_2 is not changed + - local_user_test_3 is changed + - local_user_test_4 is not changed + tags: + - user_test_local_mode |