initial_users.yml 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ---
  2. # Intended to be called on a fresh box, just to set up my users
  3. - name: Add the fdamstra account
  4. hosts: all
  5. become: yes
  6. become_user: root
  7. tasks:
  8. - name: Create fdamstra user
  9. ansible.builtin.user:
  10. name: fdamstra
  11. state: present
  12. comment: Fred Damstra
  13. shell: /bin/bash
  14. append: yes # add groups, not replace
  15. groups:
  16. - sudo
  17. home: /home/fdamstra
  18. password: "{{ password }}"
  19. update_password: on_create
  20. - name: Create authorized key
  21. authorized_key:
  22. user: fdamstra
  23. state: present
  24. key: "{{ public_ssh_key }}"
  25. - name: Set nopassword for sudo group
  26. lineinfile:
  27. path: /etc/sudoers.d/20-sudo-group-nopasswd
  28. line: '%sudo ALL=(ALL) NOPASSWD: ALL'
  29. state: present
  30. mode: 0440
  31. create: yes
  32. validate: 'visudo -cf %s'
  33. - name: Install public key
  34. copy:
  35. dest: /home/fdamstra/.ssh/id_ed25519.pub
  36. content: "{{ public_ssh_key }}"
  37. mode: 0644
  38. owner: fdamstra
  39. - name: Install private key
  40. copy:
  41. dest: /home/fdamstra/.ssh/id_ed25519
  42. content: "{{ private_ssh_key }}"
  43. mode: 0600
  44. owner: fdamstra