Skip to content

Commit

Permalink
Add sudoers_file option
Browse files Browse the repository at this point in the history
  • Loading branch information
G. Roggemans committed Jun 24, 2017
1 parent 35708f8 commit 3c0fb7f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,25 @@ the sudo settings. You can use the host and group lists to specify users
settings per host or group off hosts. The `sudo_grouplist` variables work the
same way, but for group based sudo settings (name will be prepended with `%`).

The sudo lists allows you to define which users/groups sudo settings must be
managed. Each item in the list can have following attributes:
Each item in the list should have a `name`and optionaly a `sudo` rule list and
a `sudoers_file` variable to specify a custom filename. This way you can use
the same list that you pass to your user management role.

```yaml
sudo_list:
- name: root
other_setting: 'this is ok'
sudo:
- '...'
- name: user1
sudoers_file: custom
sudo:
- '...'
- name: user3
```

The `sudo` list allows you to define one or more sudo rules. Possible
attributes for each list entry;

| Variable | Description | Required | Default |
|---------------|-------------------|----------|---------|
Expand All @@ -105,8 +122,6 @@ managed. Each item in the list can have following attributes:
| `nologoutput` | NOLOG_OUTPUT flag | no | `no` |
| `logoutput` | LOG_OUTPUT flag | no | `no` |

You can provide these attributes in a list if a user/group needs multiple entries.

###### Example `sudo_list`

```yaml
Expand All @@ -130,6 +145,7 @@ sudo_list:
sudo_grouplist:
- name: group1
sudoers_file: 50custom-group-rules
sudo:
hosts: ALL
as: ALL
Expand Down
6 changes: 3 additions & 3 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ galaxy_info:
description: A role for managing sudo.
company: GROG
license: MIT
min_ansible_version: 1.9
min_ansible_version: 2.0
platforms:
- name: GenericUNIX
versions:
Expand All @@ -29,5 +29,5 @@ dependencies:
- name: sudo
package_list_host: []
package_list_group: []
when: >
(sudo_package|string in 'True,true,Yes,yes')
when:
- sudo_package|bool
7 changes: 3 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
group: root
mode: 0440
validate: visudo -cf %s
when: sudo_default_sudoers|string in 'True.true.Yes.yes'
# Checked as string to make sure it can be specified from the command line.
when: sudo_default_sudoers|bool

- name: Enable sudoers.d
lineinfile:
Expand Down Expand Up @@ -55,7 +54,7 @@
- name: Apply sudoers group configuration
template:
src: 'etc-sudoers.d-group_template.j2'
dest: "{{ sudo_sudoersd_dir }}/10{{ item.name }}"
dest: "{{ sudo_sudoersd_dir }}/10{{ item.sudoers_file|default(item.name) }}"
owner: root
group: root
mode: 0440
Expand All @@ -69,7 +68,7 @@
- name: Apply sudoers user configuration
template:
src: 'etc-sudoers.d-user_template.j2'
dest: "{{ sudo_sudoersd_dir }}/20{{ item.name }}"
dest: "{{ sudo_sudoersd_dir }}/20{{ item.sudoers_file|default(item.name) }}"
owner: root
group: root
mode: 0440
Expand Down

0 comments on commit 3c0fb7f

Please sign in to comment.