mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
make password locking in user module idempotent (#43671)
* Simplify logic and add FreeBSD & NetBSD * Remove incorrect flag for lock and unlock on FreeBSD * Add tests and changelog Co-authored-by: Chris Gadd <gaddman@email.com>
This commit is contained in:
committed by
Sam Doran
parent
d7975462da
commit
f75a84e382
@@ -628,3 +628,111 @@
|
||||
file:
|
||||
path: "{{ output_dir }}/test_id_rsa"
|
||||
state: absent
|
||||
when: ansible_os_family == 'FreeBSD'
|
||||
|
||||
|
||||
## password lock
|
||||
- block:
|
||||
- name: Set password for ansibulluser
|
||||
user:
|
||||
name: ansibulluser
|
||||
password: "$6$rounds=656000$TT4O7jz2M57npccl$33LF6FcUMSW11qrESXL1HX0BS.bsiT6aenFLLiVpsQh6hDtI9pJh5iY7x8J7ePkN4fP8hmElidHXaeD51pbGS."
|
||||
|
||||
- name: Lock account
|
||||
user:
|
||||
name: ansibulluser
|
||||
password_lock: yes
|
||||
register: password_lock_1
|
||||
|
||||
- name: Lock account again
|
||||
user:
|
||||
name: ansibulluser
|
||||
password_lock: yes
|
||||
register: password_lock_2
|
||||
|
||||
- name: Unlock account
|
||||
user:
|
||||
name: ansibulluser
|
||||
password_lock: no
|
||||
register: password_lock_3
|
||||
|
||||
- name: Unlock account again
|
||||
user:
|
||||
name: ansibulluser
|
||||
password_lock: no
|
||||
register: password_lock_4
|
||||
|
||||
- name: Ensure task reported changes appropriately
|
||||
assert:
|
||||
msg: The password_lock tasks did not make changes appropriately
|
||||
that:
|
||||
- password_lock_1 is changed
|
||||
- password_lock_2 is not changed
|
||||
- password_lock_3 is changed
|
||||
- password_lock_4 is not changed
|
||||
|
||||
- name: Lock account
|
||||
user:
|
||||
name: ansibulluser
|
||||
password_lock: yes
|
||||
|
||||
- name: Verify account lock for BSD
|
||||
block:
|
||||
- name: BSD | Get account status
|
||||
shell: "{{ status_command[ansible_facts['system']] }}"
|
||||
register: account_status_locked
|
||||
|
||||
- name: Unlock account
|
||||
user:
|
||||
name: ansibulluser
|
||||
password_lock: no
|
||||
|
||||
- name: BSD | Get account status
|
||||
shell: "{{ status_command[ansible_facts['system']] }}"
|
||||
register: account_status_unlocked
|
||||
|
||||
- name: FreeBSD | Ensure account is locked
|
||||
assert:
|
||||
that:
|
||||
- "'LOCKED' in account_status_locked.stdout"
|
||||
- "'LOCKED' not in account_status_unlocked.stdout"
|
||||
when: ansible_facts['system'] == 'FreeBSD'
|
||||
|
||||
when: ansible_facts['system'] in ['FreeBSD', 'OpenBSD']
|
||||
|
||||
- name: Verify account lock for Linux
|
||||
block:
|
||||
- name: LINUX | Get account status
|
||||
getent:
|
||||
database: shadow
|
||||
key: ansibulluser
|
||||
|
||||
- name: LINUX | Ensure account is locked
|
||||
assert:
|
||||
that:
|
||||
- getent_shadow['ansibulluser'][0].startswith('!')
|
||||
|
||||
- name: Unlock account
|
||||
user:
|
||||
name: ansibulluser
|
||||
password_lock: no
|
||||
|
||||
- name: LINUX | Get account status
|
||||
getent:
|
||||
database: shadow
|
||||
key: ansibulluser
|
||||
|
||||
- name: LINUX | Ensure account is unlocked
|
||||
assert:
|
||||
that:
|
||||
- not getent_shadow['ansibulluser'][0].startswith('!')
|
||||
|
||||
when: ansible_facts['system'] == 'Linux'
|
||||
|
||||
always:
|
||||
- name: Unlock account
|
||||
user:
|
||||
name: ansibulluser
|
||||
password_lock: no
|
||||
|
||||
when: ansible_facts['system'] in ['FreeBSD', 'OpenBSD', 'Linux']
|
||||
|
||||
@@ -3,3 +3,7 @@ user_home_prefix:
|
||||
FreeBSD: '/home'
|
||||
SunOS: '/home'
|
||||
Darwin: '/Users'
|
||||
|
||||
status_command:
|
||||
OpenBSD: "grep ansibulluser /etc/master.passwd | cut -d ':' -f 2"
|
||||
FreeBSD: 'pw user show ansibulluser'
|
||||
|
||||
Reference in New Issue
Block a user