From b3d9897a90433fa7d71fbd6f8e8c5173fd89731a Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Mon, 1 Jun 2026 23:34:46 +0300 Subject: [PATCH] =?UTF-8?q?add=20script=20=D0=B4=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=8F=D1=82=D1=8C=20=D1=8D=D1=82=D0=BE=D0=BC=D1=83=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BF=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap-new-client.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 bootstrap-new-client.yml diff --git a/bootstrap-new-client.yml b/bootstrap-new-client.yml new file mode 100644 index 0000000..31a9eab --- /dev/null +++ b/bootstrap-new-client.yml @@ -0,0 +1,34 @@ +--- +- name: Bootstrap local known_hosts from inventory + hosts: localhost + gather_facts: false + + tasks: + - name: Ensure local ~/.ssh directory exists + ansible.builtin.file: + path: "{{ lookup('env', 'HOME') }}/.ssh" + state: directory + mode: "0700" + + - name: Add VM host keys to local known_hosts + ansible.builtin.known_hosts: + path: "{{ lookup('env', 'HOME') }}/.ssh/known_hosts" + name: "{{ hostvars[item][\"ansible_host\"] }}" + key: "{{ lookup('pipe', 'ssh-keyscan -H ' ~ hostvars[item][\"ansible_host\"]) }}" + state: present + loop: "{{ groups[\"proxmox_vms\"] }}" + +- name: Add this client SSH public key to VM user + hosts: proxmox_vms + gather_facts: false + + vars: + target_user: vrubel + key_file: "{{ lookup('env', 'HOME') }}/.ssh/id_ed25519.pub" + + tasks: + - name: Add public key to authorized_keys + ansible.posix.authorized_key: + user: "{{ target_user }}" + state: present + key: "{{ lookup('file', key_file) }}"