2024-09-18 10:08:38 +00:00
|
|
|
- name: Configure system
|
2024-09-18 12:10:57 +00:00
|
|
|
hosts: "{{ target_host }}"
|
2024-09-18 10:08:38 +00:00
|
|
|
become: yes
|
|
|
|
|
2024-09-26 04:46:47 +00:00
|
|
|
vars_files:
|
|
|
|
- vars/user-vars.yml
|
|
|
|
|
2024-09-18 10:08:38 +00:00
|
|
|
tasks:
|
2024-09-26 04:46:47 +00:00
|
|
|
- name: Create a user
|
2024-09-18 10:08:38 +00:00
|
|
|
user:
|
2024-09-26 04:46:47 +00:00
|
|
|
name: "{{ username }}"
|
|
|
|
password: "{{ '{{ password }}' | password_hash('sha512') }}"
|
|
|
|
shell: /bin/bash
|
2024-09-18 10:08:38 +00:00
|
|
|
state: present
|
|
|
|
|
2024-09-26 04:46:47 +00:00
|
|
|
- name: Add user to sudoers group
|
2024-09-18 10:08:38 +00:00
|
|
|
user:
|
2024-09-26 04:46:47 +00:00
|
|
|
name: "{{ username }}"
|
2024-09-18 10:08:38 +00:00
|
|
|
groups: sudo
|
|
|
|
append: yes
|
|
|
|
|
2024-09-26 04:46:47 +00:00
|
|
|
- name: Ensure .ssh directory exists for user
|
2024-09-18 10:08:38 +00:00
|
|
|
file:
|
2024-09-27 07:33:36 +00:00
|
|
|
path: /home/{{ username }}/.ssh
|
2024-09-18 10:08:38 +00:00
|
|
|
state: directory
|
2024-09-26 04:46:47 +00:00
|
|
|
owner: "{{ username }}"
|
|
|
|
group: "{{ username }}"
|
2024-09-18 10:08:38 +00:00
|
|
|
mode: '0700'
|
2024-09-23 13:29:16 +00:00
|
|
|
|
2024-09-26 04:46:47 +00:00
|
|
|
- name: Copy SSH public key to authorized_keys
|
|
|
|
copy:
|
|
|
|
src: "{{ path_to_ssh_key }}"
|
|
|
|
dest: /home/{{ username }}/.ssh/authorized_keys
|
|
|
|
owner: "{{ username }}"
|
|
|
|
group: "{{ username }}"
|
|
|
|
mode: '0600'
|
|
|
|
|
|
|
|
- name: Add user to sudoers for passwordless sudo
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/sudoers
|
|
|
|
state: present
|
|
|
|
regexp: '^{{ username }} ALL=\(ALL\) NOPASSWD:ALL'
|
|
|
|
line: '{{ username }} ALL=(ALL) NOPASSWD:ALL'
|
|
|
|
validate: 'visudo -cf %s'
|