Skip to content

Commit 80d5670

Browse files
committed
refactor: ostree support, simplify tests, lint issues
Add support for ostree systems. Simplify tests by adding setup and cleanup task files. Fix some lint, good practices issues
1 parent 6d34569 commit 80d5670

File tree

19 files changed

+235
-274
lines changed

19 files changed

+235
-274
lines changed

.ostree/packages-runtime.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sudo

README.md

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ Consider reading sudo documentation before setting it up.
99

1010
### Collection requirements
1111

12-
None.
12+
The role requires external collections only for management of `rpm-ostree`
13+
nodes. Please run the following command to install them if you need to manage
14+
`rpm-ostree` nodes:
15+
16+
```bash
17+
ansible-galaxy collection install -vv -r meta/collection-requirements.yml
18+
```
1319

1420
## Role Variables
1521

@@ -30,8 +36,8 @@ Type: `bool`
3036
***Dangerous!*** Setting this to `true` removes each existing sudoers file in the `include_directories` dictionary that are not defined in the`sudo_sudoers_files` variable.
3137
This allows for enforcing a desired state.
3238

33-
Default: `false`
34-
Type: `bool`
39+
Default: `false`
40+
Type: `bool`
3541

3642
### sudo_visudo_path
3743

@@ -114,7 +120,7 @@ Optional, a list of directories that your configurations must include.
114120

115121
This is a list of fully-qualified paths to directories to include via the `#includedir` option of a sudoers configuration.
116122

117-
Type: `list`
123+
Type: `list`
118124

119125
#### user_specifications
120126

@@ -147,25 +153,25 @@ You can use a defined `cmnd_alias` name as well as commands.
147153
Example definition:
148154

149155
```yaml
150-
sudo_sudoers_files:
151-
- path: /etc/sudoers.d/pingers
152-
user_specifications:
153-
- users:
154-
- root
155-
hosts:
156-
- ALL
157-
operators:
158-
- ALL
159-
commands:
160-
- ALL
161-
- users:
162-
- "%wheel"
163-
hosts:
164-
- ALL
165-
operators:
166-
- ALL
167-
commands:
168-
- ALL
156+
sudo_sudoers_files:
157+
- path: /etc/sudoers.d/pingers
158+
user_specifications:
159+
- users:
160+
- root
161+
hosts:
162+
- ALL
163+
operators:
164+
- ALL
165+
commands:
166+
- ALL
167+
- users:
168+
- "%wheel"
169+
hosts:
170+
- ALL
171+
operators:
172+
- ALL
173+
commands:
174+
- ALL
169175
```
170176

171177
#### default_overrides
@@ -194,31 +200,31 @@ List of `user_alias` names as well as individual user names to override specific
194200
Example Definition:
195201

196202
```yaml
197-
sudo_sudoers_files:
198-
- path: /etc/sudoers.d/pingers
199-
default_overrides:
200-
- type: user
201-
defaults:
202-
- "!requiretty"
203-
users:
204-
- PINGERS
205-
- type: runas
206-
defaults:
207-
- "!set_logname"
208-
operators:
209-
- root
210-
- type: host
211-
defaults:
212-
- "!requiretty"
213-
- "!requiretty"
214-
hosts:
215-
- host1
216-
- host2
217-
- type: command
218-
defaults:
219-
- "!requiretty"
220-
commands:
221-
- /usr/bin/ls
203+
sudo_sudoers_files:
204+
- path: /etc/sudoers.d/pingers
205+
default_overrides:
206+
- type: user
207+
defaults:
208+
- "!requiretty"
209+
users:
210+
- PINGERS
211+
- type: runas
212+
defaults:
213+
- "!set_logname"
214+
operators:
215+
- root
216+
- type: host
217+
defaults:
218+
- "!requiretty"
219+
- "!requiretty"
220+
hosts:
221+
- host1
222+
- host2
223+
- type: command
224+
defaults:
225+
- "!requiretty"
226+
commands:
227+
- /usr/bin/ls
222228
```
223229

224230
## Example Playbooks
@@ -241,16 +247,16 @@ Example Definition:
241247
hosts: all
242248
vars:
243249
sudoers_files:
244-
- path: /etc/sudoers
245-
user_specifications:
246-
- users:
247-
- root
248-
hosts:
249-
- x
250-
commands:
251-
- /usr/bin/ls
250+
- path: /etc/sudoers
251+
user_specifications:
252+
- users:
253+
- root
254+
hosts:
255+
- x
256+
commands:
257+
- /usr/bin/ls
252258
roles:
253-
- role: linux-system-roles.sudo
259+
- role: linux-system-roles.sudo
254260
```
255261

256262
### Applying defaults
@@ -428,6 +434,10 @@ Example Definition:
428434
- root
429435
```
430436

437+
## rpm-ostree
438+
439+
See README-ostree.md
440+
431441
## License
432442

433443
MIT

meta/collection-requirements.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
collections:
3+
- name: ansible.posix

tasks/main.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
---
2+
- name: Set version specific variables
3+
include_tasks: set_vars.yml
4+
25
- name: Ensure sudo is installed
36
package:
4-
name: sudo
7+
name: "{{ __sudo_packages }}"
58
state: present
9+
use: "{{ (__sudo_is_ostree | d(false)) |
10+
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
611

712
- name: Set include directories variable
813
set_fact:
@@ -37,7 +42,7 @@
3742
with_items: "{{ sudo_sudoers_files }}"
3843
loop_control:
3944
label: "{{ item.path }}"
40-
when: item.path != '/etc/sudoers'
45+
when: item.path != "/etc/sudoers"
4146

4247
- name: Ensure /etc/sudoers is configured
4348
template:
@@ -51,7 +56,7 @@
5156
loop_control:
5257
label: "{{ item.path }}"
5358
when:
54-
- item.path == '/etc/sudoers'
59+
- item.path == "/etc/sudoers"
5560
- sudo_rewrite_default_sudoers_file | bool
5661

5762
- name: Remove unauthorized included sudoer files
@@ -70,8 +75,8 @@
7075
- name: Set unauthorized included sudoers files variable
7176
set_fact:
7277
sudo_unauthorized_files: "{{ sudo_existing_included_files['files']
73-
| selectattr('path', 'defined') | map(attribute='path')
74-
| flatten | difference(sudo_file_paths) }}"
78+
| selectattr('path', 'defined') | map(attribute='path')
79+
| flatten | difference(sudo_file_paths) }}"
7580

7681
- name: Remove unauthorized included sudoers files
7782
file:

tasks/set_vars.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
- name: Ensure ansible_facts used by role
33
setup:
4-
gather_subset: "{{ __template_required_facts_subsets }}"
5-
when: __template_required_facts |
4+
gather_subset: "{{ __sudo_required_facts_subsets }}"
5+
when: __sudo_required_facts |
66
difference(ansible_facts.keys() | list) | length > 0
77

88
- name: Determine if system is ostree and set flag
9-
when: not __template_is_ostree is defined
9+
when: not __sudo_is_ostree is defined
1010
block:
1111
- name: Check if system is ostree
1212
stat:
@@ -15,7 +15,7 @@
1515

1616
- name: Set flag to indicate system is ostree
1717
set_fact:
18-
__template_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"
18+
__sudo_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"
1919

2020
- name: Set platform/version specific variables
2121
include_vars: "{{ __vars_file }}"

templates/sudoers.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
{% for spec_default in spec.defaults %}
2222
{% set _ = _spec_default.append(spec_default) %}
2323
{% endfor %}
24-
Defaults{{ sign }} {{ _spec_original | join(", ")}} {{ _spec_default |
25-
join(", ")}}
24+
Defaults{{ sign }} {{ _spec_original | join(", ") }} {{ _spec_default |
25+
join(", ") }}
2626
{% endif %}
2727
{% endmacro -%}
2828
{{ ansible_managed | default('Ansible managed') | comment }}
@@ -164,7 +164,7 @@ Defaults {{ default }}
164164
#include {{ file }}
165165
{% endfor %}
166166
{% endif %}
167-
{% if item.include_directories is defined and item.include_directories |
167+
{% if item.include_directories is defined and item.include_directories |
168168
length > 0 %}
169169
## Include directories
170170
{% for dir in item.include_directories %}

tests/roles/linux-system-roles.template/defaults

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/roles/linux-system-roles.template/handlers

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/roles/linux-system-roles.template/meta

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/roles/linux-system-roles.template/tasks

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)