You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
758 B
YAML
34 lines
758 B
YAML
# https://stackoverflow.com/questions/37333305/ansible-create-a-user-with-sudo-privileges
|
|
- name: Install Sudo
|
|
apt:
|
|
pkg:
|
|
- sudo
|
|
state: latest
|
|
update_cache: true
|
|
|
|
- name: Make sure we have a groups
|
|
group:
|
|
name: '{{item.group}}'
|
|
state: present
|
|
with_items: '{{users}}'
|
|
|
|
- name: Add Users
|
|
ansible.builtin.user:
|
|
name: '{{item.name}}'
|
|
comment: '{{item.name}} user'
|
|
group: '{{item.group}}'
|
|
with_items: '{{users}}'
|
|
|
|
- name: Add sudoers
|
|
template:
|
|
src: sudoers.j2
|
|
dest: /etc/sudoers.d/{{item.name}}
|
|
with_items: '{{users}}'
|
|
when: item.passwordless_sudo == true
|
|
|
|
- name: Set authorized key
|
|
authorized_key:
|
|
user: '{{homelab_user}}'
|
|
state: present
|
|
key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
|