From 3a12b0614016cd431ce3cc50c6a1773bc649c5c5 Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 20 Jul 2025 18:58:45 +0200 Subject: [PATCH] Add sudoers.yml --- sudoers.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 sudoers.yml diff --git a/sudoers.yml b/sudoers.yml new file mode 100644 index 0000000..47ee8e7 --- /dev/null +++ b/sudoers.yml @@ -0,0 +1,29 @@ +--- +- name: Configure visudo for secure sudoers + hosts: all + become: yes + tasks: + - name: Allow admin group passwordless sudo + copy: + dest: /etc/sudoers.d/admin + content: "%{{ ansible_user }} ALL=(ALL) NOPASSWD:ALL" + owner: root + group: root + mode: '0440' + +##For a specific user + +--- +- name: Add linuxadmin to sudoers + hosts: all + become: yes + tasks: + - name: Ensure linuxadmin can sudo without a password + lineinfile: + path: /etc/sudoers + state: present + regexp: '^linuxadmin' + line: 'linuxadmin ALL=(ALL) NOPASSWD: ALL' + validate: 'visudo -cf %s' + +#Just replace linuxadmin with the user you want to add to the sudo group. \ No newline at end of file