Advertisement
wagnermarques

add user to sudoers file

Jan 19th, 2023
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | Source Code | 0 0
  1. - name: Load environment variables
  2. ansible.builtin.set_fact:
  3. env: "{{ lookup('pipe', 'dotenv -f .env') }}"
  4.  
  5. - name: Add user to sudoers
  6. hosts: all
  7. gather_facts: yes
  8. vars:
  9. username: "{{ env.USERNAME | default('aluno') }}"
  10. package: "sudo"
  11. tasks:
  12. - name: Install Sudo
  13. package:
  14. name: "{{ package }}"
  15. state: present
  16. - name: Add user to sudoers file
  17. become: yes
  18. lineinfile:
  19. path: /etc/sudoers
  20. line: "{{ username }} ALL=(ALL) NOPASSWD:ALL"
  21. state: present
  22. validate: 'visudo -cf %s'
  23. #from chatGPT
Tags: ansible
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement