This site won't get any more updates, see github repo for most recent docs.
This role installs sudo and deploy sudoers files into sudoers.d. For the sudoers items it makes use of community.general.sudoers. There you can see what items a sudoers dict item can hold. You can define sudoers items on multiple layers.
Put sudoers rules into host_vars/yourhostname.yml
.
sudo_sudoers_host:
- name: "test sudorecord"
state: present
user: testuser
commands:
- "/usr/bin/ls"
Put sudoers rules into a variable where all hosts that need it will see, e.g. group_vars/all.yml
.
sudo_sudoers_group:
webservers:
- name: "test sudorecord"
state: present
user: testuser
commands:
- "/usr/bin/ls"
This way only the hosts in the Ansible group webservers
will get this rule.
If you need sudo rules for your playbook or your role, you can call this very role and assign sudo rules by setting this variable.
sudo_sudoers_role:
- name: "some other sudorecord"
state: present
user: testuser2
commands:
- "/usr/bin/cat"
Here is an example how to outsource sudoers tasks to this role:
- name: Set installrole var
ansible.builtin.set_fact:
sudo_sudoers_role:
- name: "some other sudorecord2"
state: present
user: testuser3
commands:
- "/usr/bin/top"
- name: run sudo role
ansible.builtin.include_role:
name: imp1sh.ansible_managemynetwork.ansible_sudo