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