ansible/roles/users/tasks/main.yml
2024-09-06 21:32:54 +02:00

39 lines
809 B
YAML

- name: Test connection as current user
block:
- name: Ping
ping:
# data: crash
rescue:
- name: Set ansible_user to root
set_fact:
ansible_user: root
- name: Install sudo
apt:
pkg:
- sudo
- name: Create users
user:
name: "{{ item.username }}"
home: "/home/{{ item.username }}"
move_home: true
shell: "{{ item.shell|default('/bin/bash') }}"
groups: sudo
loop: "{{ users }}"
become: true
- name: Add ssh keys
ansible.posix.authorized_key:
user: "{{ item.username }}"
key: "{{ item.pubkeys }}"
exclusive: true
loop: "{{ users }}"
- name: Change sudo policy
lineinfile:
path: /etc/sudoers
regexp: "^%sudo ALL="
line: "%sudo ALL=(ALL) NOPASSWD: ALL"
validate: /usr/sbin/visudo -cf %s
become: true