First commit

This commit is contained in:
2024-07-16 09:37:27 +02:00
commit 7f2f5ad1ae
3 changed files with 164 additions and 0 deletions

40
setup_ssh.yml Normal file
View File

@@ -0,0 +1,40 @@
- name: Configure SSH
hosts: athelas
tasks:
- name: Generate RSA4096 SSH key
community.crypto.openssh_keypair:
path: "~/ssh_key"
size: 4096
- name: Get SSH Key
ansible.builtin.fetch:
dest: "~/ansible/keys"
src: "~/ssh_key"
- name: Copy new SSH configuration
ansible.builtin.template:
src: "templates/sshd_config.j2"
dest: "/etc/ssh/sshd_config"
- name: Generate password
ansible.builtin.command: openssl rand -base64 12
register: rand
- name: Create new user
ansible.builtin.user:
name: "test"
groups: "sudo"
append: true
password: "{{ rand.stdout | password_hash('sha512') }}"
become: true
- name: Display new user's password
ansible.builtin.debug:
msg: "New password is {{ rand.stdout }}"
- name: Add SSH public key to remote host
ansible.builtin.authorized_key:
user: "test"
key: "{{ lookup('file', '~/ssh_key') }}"
become: true