32 lines
1.7 KiB
YAML
32 lines
1.7 KiB
YAML
- name: Setup new administrative user
|
|||
|
|
hosts: tatooine
|
||
|
|
become: yes # This tells Ansible to run as root
|
||
|
|
remote_user: root
|
||
|
|
vars:
|
||
|
|
new_user: "volker"
|
||
|
|
# Replace this with your actual public key string or a path to the file
|
||
|
|
ssh_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCqKm6tSG73CudRxZkUnR/hcwKQnvSfkQM/Gq1gR6wswu4kcthHZ+YCxzRFIJmTR1+C0UXy8yRVtwprz31plFbHvU3Om913MGaN1oadunYOkKD8OmAtCtht9H+5wC5HtjwuhNf/MH1K727ecNUSH10DYovzXkOD6byJukfkvbU6CVKxWAI6W9PXTLOPRyUoy3TX0GEBascayneqHBFfPGpICnR76X9Ydi2avfgmNiGtTMzKkn1mNqm3a4eHCfde8XUBtqlxdMnO/pMlgMh14XoBSD5T+U3OqIUvMOiU3ZKlcq4W46wtPX1Im6iqfgFutwT1YqQ8UNY06urO41nH6d5rVfSA1BS7Fonho2xK5lQ3aqapn2+o9goXTIQ1avoOHyWS0j+W8m5BEL8Prvr+eqjTCivh5g4rKVe2SebKzZU89oZSEkV9Mj69qhS1g3LnyJds+oskl04CdRXrn5KSyxXP9X4m0EYYfbzWMAPRZ6SsltAOw9w4hwZtwIKSl2+bMQAqQmRojDof4FgK+DCQfdcThhrmknGtGiL1v3tJuCmmiikoKis5qOVBmVJOhJaSOTKSIhx3oTVVfCgzlEnGE0M7gUk1+Qh30p4TahsbyfcWg5v3+0vdIVgAWIdW0Kp0s9R0mU4qKeIuZ9ejHCmaGcQe2ZolQZc5UrTwMBb1PaqPQQ== key von macbook fuer rogueone"
|
||
|
|
|
||
|
|
tasks:
|
||
|
|
- name: Ensure the user exists
|
||
|
|
ansible.builtin.user:
|
||
|
|
name: "{{ new_user }}"
|
||
|
|
state: present
|
||
|
|
shell: /bin/bash
|
||
|
|
groups: sudo # Use 'wheel' if you are on RHEL/CentOS/Fedora
|
||
|
|
append: yes # Ensures you don't remove them from other groups
|
||
|
|
|
||
|
|
- name: Set up authorized keys for the new user
|
||
|
|
ansible.builtin.authorized_key:
|
||
|
|
user: "{{ new_user }}"
|
||
|
|
state: present
|
||
|
|
key: "{{ ssh_public_key }}"
|
||
|
|
|
||
|
|
- name: Allow the user to use sudo without a password (Optional)
|
||
|
|
ansible.builtin.lineinfile:
|
||
|
|
path: /etc/sudoers.d/{{ new_user }}
|
||
|
|
line: "{{ new_user }} ALL=(ALL) NOPASSWD:ALL"
|
||
|
|
state: present
|
||
|
|
mode: '0440'
|
||
|
|
create: yes
|