|
1 | 1 | ---
|
2 | 2 | - name: Creating groups
|
3 |
| - group: name="{{item.name}}" gid="{{item.gid | default(omit)}}" |
4 |
| - with_items: "{{groups_to_create}}" |
5 |
| - tags: ['users','groups','configuration'] |
| 3 | + group: |
| 4 | + name: "{{ item.name }}" |
| 5 | + gid: "{{ item.gid | default(omit) }}" |
| 6 | + with_items: "{{ groups_to_create }}" |
| 7 | + tags: ["users", "groups", "configuration"] |
6 | 8 |
|
7 | 9 | - name: Per-user group creation
|
8 |
| - group: name="{{item.username}}" |
9 |
| - gid="{{item.gid | default(item.uid) | default(omit)}}" |
10 |
| - with_items: "{{users}}" |
| 10 | + group: |
| 11 | + name: "{{ item.username }}" |
| 12 | + gid: "{{ item.gid | default(item.uid) | default(omit) }}" |
| 13 | + with_items: "{{ users }}" |
11 | 14 | when: "'group' not in item and users_create_per_user_group"
|
12 |
| - tags: ['users','configuration'] |
| 15 | + tags: ["users", "configuration"] |
13 | 16 |
|
14 | 17 | - name: User creation
|
15 | 18 | user:
|
16 |
| - name: "{{item.username}}" |
17 |
| - group: "{{item.group | default(item.username if users_create_per_user_group else users_group)}}" |
| 19 | + name: "{{ item.username }}" |
| 20 | + group: "{{ item.group | default(item.username if users_create_per_user_group else users_group) }}" |
18 | 21 | # empty string removes user from all secondary groups
|
19 |
| - groups: "{{item.groups | join(',') if 'groups' in item else ''}}" |
20 |
| - append: "{{item.append | default(omit)}}" |
21 |
| - shell: "{{item.shell if item.shell is defined else users_default_shell}}" |
22 |
| - password: "{{item.password if item.password is defined else '!'}}" |
23 |
| - comment: "{{item.name if item.name is defined else ''}}" |
24 |
| - uid: "{{item.uid | default(omit)}}" |
| 22 | + groups: "{{ item.groups | join(',') if 'groups' in item else '' }}" |
| 23 | + append: "{{ item.append | default(omit) }}" |
| 24 | + shell: "{{ item.shell if item.shell is defined else users_default_shell }}" |
| 25 | + password: "{{ item.password if item.password is defined else '!' }}" |
| 26 | + comment: "{{ item.name if item.name is defined else '' }}" |
| 27 | + uid: "{{ item.uid | default(omit) }}" |
25 | 28 | home: "{{ item.home | default('/home/' + item.username) }}"
|
26 |
| - createhome: "{{'yes' if users_create_homedirs else 'no'}}" |
| 29 | + createhome: "{{ 'yes' if users_create_homedirs else 'no' }}" |
27 | 30 | generate_ssh_key: "{{ item.generate_ssh_key | default(omit) }}"
|
28 |
| - update_password: "{{item.update_password | default(omit)}}" |
29 |
| - with_items: "{{users}}" |
30 |
| - tags: ['users','configuration'] |
| 31 | + update_password: "{{ item.update_password | default(omit) }}" |
| 32 | + with_items: "{{ users }}" |
| 33 | + tags: ["users", "configuration"] |
31 | 34 |
|
32 | 35 | - name: SSH keys
|
33 | 36 | authorized_key:
|
34 |
| - user: "{{item.0.username}}" |
35 |
| - key: "{{item.1}}" |
| 37 | + user: "{{ item.0.username }}" |
| 38 | + key: "{{ item.1 }}" |
36 | 39 | path: "{{ item.0.home | default('/home/' + item.0.username) }}/{{ authorized_keys_file }}"
|
37 | 40 | with_subelements:
|
38 |
| - - "{{users}}" |
| 41 | + - "{{ users }}" |
39 | 42 | - ssh_key
|
40 | 43 | - skip_missing: yes
|
41 |
| - tags: ['users','configuration'] |
| 44 | + tags: ["users", "configuration"] |
42 | 45 |
|
43 | 46 | - name: Setup user profiles
|
44 | 47 | blockinfile:
|
45 |
| - block: "{{item.profile}}" |
| 48 | + block: "{{ item.profile }}" |
46 | 49 | dest: "{{ item.home | default('/home/' + item.username) }}/.profile"
|
47 |
| - owner: "{{item.username}}" |
48 |
| - group: "{{item.group | default(item.username if users_create_per_user_group else users_group)}}" |
| 50 | + owner: "{{ item.username }}" |
| 51 | + group: "{{ item.group | default(item.username if users_create_per_user_group else users_group) }}" |
49 | 52 | mode: 0644
|
50 | 53 | create: true
|
51 | 54 | when: users_create_homedirs and item.profile is defined
|
52 |
| - with_items: "{{users}}" |
| 55 | + with_items: "{{ users }}" |
53 | 56 |
|
54 | 57 | - name: Deleted user removal
|
55 | 58 | user:
|
56 |
| - name: "{{item.username}}" |
| 59 | + name: "{{ item.username }}" |
57 | 60 | state: absent
|
58 |
| - remove: "{{item.remove | default(omit)}}" |
59 |
| - force: "{{item.force | default(omit)}}" |
60 |
| - with_items: "{{users_deleted}}" |
61 |
| - tags: ['users','configuration'] |
| 61 | + remove: "{{ item.remove | default(omit) }}" |
| 62 | + force: "{{ item.force | default(omit) }}" |
| 63 | + with_items: "{{ users_deleted }}" |
| 64 | + tags: ["users", "configuration"] |
62 | 65 |
|
63 | 66 | - name: Deleted per-user group removal
|
64 |
| - group: name="{{item.username}}" state=absent |
65 |
| - with_items: "{{users_deleted}}" |
| 67 | + group: |
| 68 | + name: "{{ item.username }}" |
| 69 | + state: absent |
| 70 | + with_items: "{{ users_deleted }}" |
66 | 71 | when: users_create_per_user_group
|
67 |
| - tags: ['users','configuration'] |
| 72 | + tags: ["users", "configuration"] |
0 commit comments