39 lines
809 B
YAML
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
|