Debian Codegraph @

test/integration/targets/user/tasks/test_password_lock.yml

raw
1 - name: Test password lock
2 when: ansible_facts.system in ['FreeBSD', 'OpenBSD', 'Linux']
3 block:
4 - name: Remove ansibulluser
5 user:
6 name: ansibulluser
7 state: absent
8 remove: yes
9
10 - name: Create ansibulluser with password
11 user:
12 name: ansibulluser
13 password: "$6$rounds=656000$TT4O7jz2M57npccl$33LF6FcUMSW11qrESXL1HX0BS.bsiT6aenFLLiVpsQh6hDtI9pJh5iY7x8J7ePkN4fP8hmElidHXaeD51pbGS."
14
15 - name: Lock account without password parameter
16 user:
17 name: ansibulluser
18 password_lock: yes
19 register: password_lock_1
20
21 - name: Lock account without password parameter again
22 user:
23 name: ansibulluser
24 password_lock: yes
25 register: password_lock_2
26
27 - name: Unlock account without password parameter
28 user:
29 name: ansibulluser
30 password_lock: no
31 register: password_lock_3
32
33 - name: Unlock account without password parameter again
34 user:
35 name: ansibulluser
36 password_lock: no
37 register: password_lock_4
38
39 - name: Lock account with password parameter
40 user:
41 name: ansibulluser
42 password_lock: yes
43 password: "$6$rounds=656000$TT4O7jz2M57npccl$33LF6FcUMSW11qrESXL1HX0BS.bsiT6aenFLLiVpsQh6hDtI9pJh5iY7x8J7ePkN4fP8hmElidHXaeD51pbGS."
44 register: password_lock_5
45
46 - name: Lock account with password parameter again
47 user:
48 name: ansibulluser
49 password_lock: yes
50 password: "$6$rounds=656000$TT4O7jz2M57npccl$33LF6FcUMSW11qrESXL1HX0BS.bsiT6aenFLLiVpsQh6hDtI9pJh5iY7x8J7ePkN4fP8hmElidHXaeD51pbGS."
51 register: password_lock_6
52
53 - name: Unlock account with password parameter
54 user:
55 name: ansibulluser
56 password_lock: no
57 password: "$6$rounds=656000$TT4O7jz2M57npccl$33LF6FcUMSW11qrESXL1HX0BS.bsiT6aenFLLiVpsQh6hDtI9pJh5iY7x8J7ePkN4fP8hmElidHXaeD51pbGS."
58 register: password_lock_7
59
60 - name: Unlock account with password parameter again
61 user:
62 name: ansibulluser
63 password_lock: no
64 password: "$6$rounds=656000$TT4O7jz2M57npccl$33LF6FcUMSW11qrESXL1HX0BS.bsiT6aenFLLiVpsQh6hDtI9pJh5iY7x8J7ePkN4fP8hmElidHXaeD51pbGS."
65 register: password_lock_8
66
67 - name: Ensure task reported changes appropriately
68 assert:
69 msg: The password_lock tasks did not make changes appropriately
70 that:
71 - password_lock_1 is changed
72 - password_lock_2 is not changed
73 - password_lock_3 is changed
74 - password_lock_4 is not changed
75 - password_lock_5 is changed
76 - password_lock_6 is not changed
77 - password_lock_7 is changed
78 - password_lock_8 is not changed
79
80 - name: Lock account
81 user:
82 name: ansibulluser
83 password_lock: yes
84
85 - name: Verify account lock for BSD
86 when: ansible_facts.system in ['FreeBSD', 'OpenBSD']
87 block:
88 - name: BSD | Get account status
89 shell: "{{ status_command[ansible_facts['system']] }}"
90 register: account_status_locked
91
92 - name: Unlock account
93 user:
94 name: ansibulluser
95 password_lock: no
96
97 - name: BSD | Get account status
98 shell: "{{ status_command[ansible_facts['system']] }}"
99 register: account_status_unlocked
100
101 - name: FreeBSD | Ensure account is locked
102 assert:
103 that:
104 - "'LOCKED' in account_status_locked.stdout"
105 - "'LOCKED' not in account_status_unlocked.stdout"
106 when: ansible_facts['system'] == 'FreeBSD'
107
108 - name: Verify account lock for Linux
109 when: ansible_facts.system == 'Linux'
110 block:
111 - name: LINUX | Get account status
112 getent:
113 database: shadow
114 key: ansibulluser
115
116 - name: LINUX | Ensure account is locked
117 assert:
118 that:
119 - getent_shadow['ansibulluser'][0].startswith('!')
120
121 - name: Unlock account
122 user:
123 name: ansibulluser
124 password_lock: no
125
126 - name: LINUX | Get account status
127 getent:
128 database: shadow
129 key: ansibulluser
130
131 - name: LINUX | Ensure account is unlocked
132 assert:
133 that:
134 - not getent_shadow['ansibulluser'][0].startswith('!')
135
136 always:
137 - name: Unlock account
138 user:
139 name: ansibulluser
140 password_lock: no