blob: 44707dc7fbecdf426267bd14cbc6dd6b55ddd028 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
- name: remove the test user
user:
name: ansibulluser
state: absent
- name: try to create a user
user:
name: ansibulluser
state: present
register: user_test0_0
- name: create the user again
user:
name: ansibulluser
state: present
register: user_test0_1
- debug:
var: user_test0
verbosity: 2
- name: make a list of users
script: userlist.sh {{ ansible_facts.distribution }}
register: user_names
- debug:
var: user_names
verbosity: 2
- name: validate results for testcase 0
assert:
that:
- user_test0_0 is changed
- user_test0_1 is not changed
- '"ansibulluser" in user_names.stdout_lines'
- name: run existing user check tests
user:
name: "{{ user_names.stdout_lines | random }}"
state: present
create_home: no
loop: "{{ range(1, 5+1) | list }}"
register: user_test1
- debug:
var: user_test1
verbosity: 2
- name: validate results for testcase 1
assert:
that:
- user_test1.results is defined
- user_test1.results | length == 5
- name: validate changed results for testcase 1
assert:
that:
- "user_test1.results[0] is not changed"
- "user_test1.results[1] is not changed"
- "user_test1.results[2] is not changed"
- "user_test1.results[3] is not changed"
- "user_test1.results[4] is not changed"
- "user_test1.results[0]['state'] == 'present'"
- "user_test1.results[1]['state'] == 'present'"
- "user_test1.results[2]['state'] == 'present'"
- "user_test1.results[3]['state'] == 'present'"
- "user_test1.results[4]['state'] == 'present'"
- name: register user informations
when: ansible_facts.system == 'Darwin'
command: dscl . -read /Users/ansibulluser
register: user_test2
- name: validate user defaults for MacOS
when: ansible_facts.system == 'Darwin'
assert:
that:
- "'RealName: ansibulluser' in user_test2.stdout_lines "
- "'PrimaryGroupID: 20' in user_test2.stdout_lines "
#https://github.com/ansible/ansible/issues/82490
- name: Create a new user with custom shell to test ~ expansion
user:
name: randomuserthomas
shell: ~/custom_shell
register: user_create_result
- name: Create a new user with custom shell to test ~ expansion second time should show ok not changed
user:
name: randomuserthomas
shell: ~/custom_shell
register: user_creation_result
- name: Assert that the user with a tilde in the shell path is created
assert:
that:
- user_creation_result is not changed
- user_create_result is changed
- name: remove the randomuserthomas user to clean up
user:
name: randomuserthomas
state: absent
force: true
|