Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the possibility to define additional sudoers files. #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ sudo_users: []
sudo_defaults: []
# default sudoers file
sudo_sudoers_file: ansible
# list for additional sudoers files
sudo_sudoers_additional_files: []
# path of the sudoers.d directory
sudo_sudoers_d_path: /etc/sudoers.d
# delete other files in `sudo_sudoers_d_path`
Expand Down Expand Up @@ -114,8 +116,14 @@ This is an example playbook:
groups: 'group1,group2'
purge_other_sudoers_files: yes

```
sudo_sudoers_additional_files:
- web
sudo_users_web:
- name: 'webuser1'

```
If you are going to make use of sudo_sudoers_additional_files then all the other variables are available like before, but you have to suffix them with the filename.
This is like in the upper example the name `web`.

## Testing

Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ sudo_users: []
sudo_defaults: []
# default sudoers file
sudo_sudoers_file: ansible
# list for additional sudoers files
sudo_sudoers_additional_files: []
# path of the sudoers.d directory
sudo_sudoers_d_path: /etc/sudoers.d
# delete other files in `sudo_sudoers_d_path`
Expand Down
19 changes: 19 additions & 0 deletions tasks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
group: "{{ sudo_sudoers_group }}"
mode: "0440"

- name: "Creating additional sudoers configurations"
vars:
sudo_sudoers_user_aliases: "{{ lookup('vars', 'sudo_sudoers_user_aliases_' + item, default='') }}"
sudo_sudoers_runas_aliases: "{{ lookup('vars', 'sudo_sudoers_runas_aliases_' + item, default='') }}"
sudo_sudoers_cmnd_aliases: "{{ lookup('vars', 'sudo_sudoers_cmnd_aliases_' + item, default='') }}"
sudo_defaults: "{{ lookup('vars', 'sudo_defaults_' + item, default='') }}"
sudo_users: "{{ lookup('vars', 'sudo_users_' + item, default='') }}"
template:
src: "etc/sudoers.d/ansible.j2"
dest: "{{ sudo_sudoers_d_path }}/{{ item }}"
validate: "{{ sudo_visudo }} -cf %s"
owner: root
group: "{{ sudo_sudoers_group }}"
mode: "0440"
loop: "{{ sudo_sudoers_additional_files | list }}"
when:
- (sudo_sudoers_additional_files | length > 0)

- name: "List files in {{ sudo_sudoers_d_path }}"
find:
paths: "{{ sudo_sudoers_d_path }}"
Expand All @@ -27,3 +45,4 @@
when:
- purge_other_sudoers_files | bool
- (item.path|basename) != sudo_sudoers_file
- (item.path|basename) not in sudo_sudoers_additional_files
5 changes: 5 additions & 0 deletions tests/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@
users: 'user1,user2'
groups: 'group1,group2'
purge_other_sudoers_files: yes

sudo_sudoers_additional_files:
- web
sudo_users_web:
- name: 'webuser1'