File tree Expand file tree Collapse file tree 8 files changed +127
-0
lines changed Expand file tree Collapse file tree 8 files changed +127
-0
lines changed Original file line number Diff line number Diff line change @@ -90,3 +90,5 @@ roles/*
90
90
! roles /gateway /**
91
91
! roles /alertmanager /
92
92
! roles /alertmanager /**
93
+ ! roles /sudoers /
94
+ ! roles /sudoers /**
Original file line number Diff line number Diff line change 28
28
- import_role :
29
29
name : basic_users
30
30
31
+ - hosts : sudoers:!builder
32
+ become : true
33
+ tags : sudoers
34
+ gather_facts : yes
35
+ tasks :
36
+ - name : Configure sudoers
37
+ import_role :
38
+ name : sudoers
39
+
31
40
- name : Setup EESSI
32
41
hosts : eessi
33
42
tags : eessi
Original file line number Diff line number Diff line change
1
+ # sudoers
2
+
3
+ Manage sudoers configuration by creating files in ` /etc/sudoers.d/ ` .
4
+
5
+ ## Role Variables
6
+
7
+ - ` sudoers_groups ` : Required list. A list of dictionaries defining sudo group configurations. Each dictionary should contain:
8
+ - ` group ` : Required string. The group name to grant sudo privileges to.
9
+ - ` commands ` : Required string. The sudo commands specification (e.g., "ALL=(ALL) ALL").
10
+ - ` state ` : Optional string. Either "present" (default) or "absent" to remove the configuration.
11
+
12
+ ## Features
13
+
14
+ - Creates individual sudoers files for each group in ` /etc/sudoers.d/ `
15
+ - Validates sudoers syntax using ` visudo -cf ` before applying
16
+ - Sanitizes group names by replacing spaces and slashes with underscores for filename safety
17
+ - Supports removing sudoers configurations by setting ` state: absent `
18
+ - Sets proper permissions (0440) and ownership (root: root ) on sudoers files
19
+
20
+ ## Dependencies
21
+
22
+ None.
23
+
24
+ ## Example Playbook
25
+
26
+ ``` yaml
27
+ - hosts : servers
28
+ become : yes
29
+ roles :
30
+ - role : sudoers
31
+ vars :
32
+ sudoers_groups :
33
+ - group : SITE_Admins
34
+ commands : " ALL=(ALL) ALL"
35
+ - group : SITE_Users
36
+ commands : " ALL=(ALL) ALL"
37
+ - group : developers
38
+ commands : " ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart myapp"
39
+ - group : old_group
40
+ state : absent
41
+ ` ` `
42
+
43
+ ## Example Variables
44
+
45
+ ` ` ` yaml
46
+ # Merge your existing groups like this:
47
+ sudoers_groups : " {{ sudo_groups + management_sudo_groups }}"
48
+
49
+ # Where you have:
50
+ sudo_groups :
51
+ - group : SITE_Users
52
+ commands : " ALL=(ALL) ALL"
53
+
54
+ management_sudo_groups :
55
+ - group : SITE_Admins
56
+ commands : " ALL=(ALL) ALL"
57
+ ` ` `
58
+
59
+ ## License
60
+
61
+ Apache v2
62
+
63
+ ## Author Information
64
+
65
+ StackHPC Ltd.
Original file line number Diff line number Diff line change
1
+ ---
2
+ # Default variables for sudoers role
3
+
4
+ # List of sudo groups to configure
5
+ # Each item should have:
6
+ # - group: the group name (required)
7
+ # - commands: the sudo commands specification (required)
8
+ # - state: present (default) or absent (optional)
9
+ sudoers_groups : []
10
+
11
+ # Example:
12
+ # sudoers_groups:
13
+ # - group: SITE_Admins
14
+ # commands: "ALL=(ALL) ALL"
15
+ # - group: SITE_Users
16
+ # commands: "ALL=(ALL) ALL"
17
+ # - group: developers
18
+ # commands: "ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart myapp"
19
+ # - group: old_group
20
+ # state: absent
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : Configure sudoers files
3
+ template :
4
+ src : sudoers.j2
5
+ dest : /etc/sudoers.d/{{ item.group | replace(' ', '_') | replace('/', '_') }}
6
+ owner : root
7
+ group : root
8
+ mode : ' 0440'
9
+ validate : ' visudo -cf %s'
10
+ become : true
11
+ with_items : " {{ sudoers_groups }}"
12
+ when :
13
+ - sudoers_groups is defined
14
+ - sudoers_groups | length > 0
15
+
16
+ - name : Remove sudoers files for absent groups
17
+ file :
18
+ path : /etc/sudoers.d/{{ item.group | replace(' ', '_') | replace('/', '_') }}
19
+ state : absent
20
+ become : true
21
+ with_items : " {{ sudoers_groups }}"
22
+ when :
23
+ - sudoers_groups is defined
24
+ - item.state | default('present') == 'absent'
Original file line number Diff line number Diff line change
1
+ %{{ item.group }} {{ item.commands }}
Original file line number Diff line number Diff line change @@ -182,3 +182,6 @@ extra_packages
182
182
183
183
[gateway]
184
184
# Add builder to this group to install gateway ansible-init playbook into image
185
+
186
+ [sudoers]
187
+ # Hosts to configure sudoers groups
Original file line number Diff line number Diff line change @@ -125,3 +125,6 @@ builder
125
125
[gateway:children]
126
126
# Add builder to this group to install gateway ansible-init playbook into image
127
127
builder
128
+
129
+ [sudoers]
130
+ # Hosts to configure sudoers groups
You can’t perform that action at this time.
0 commit comments