Hi guys i have a task to use community.general.sudoers collection to do some configurations to sudoers file, but based on the collection documentation i didnt see a way of doing that, anyone has already used this collection for this purpose ?
The task i need to do is set some configs like the list below to a user or group, but following the collection doc i didnt find a way of doing this, seems like the collection only allow to explicitly set which commands user or group can have access by pointing to its binarie
Does this not acheive what you’re after? The only thing of note I see is that this doesn’t let you create multiple lines/rules in the same file.
Alternatively, you can use the copy, template, or lineinfile modules and use the validate: /usr/sbin/visudo -cf %s parameter to ensure the changes you make won’t break sudoers.
[van@aap sudoers]$ ansible-playbook tasks/main.yaml --user root
ERROR! 'community.general.sudoers' is not a valid attribute for a Play
The error appears to be in '/home/van/roles/sudoers/tasks/main.yaml': line 3, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Configure sudoers to enable group to execute commands
^ here
You can’t execute a tasks file as a playbook. If it’s part of a role, you need to call the role from a playbook, otherwise you can use include_tasks: to call it. (though technically you can include_tasks directly to a task file in a role if you can path to it)