From 51302033aa8058183149018492b35b59f6b743b5 Mon Sep 17 00:00:00 2001 From: djpbessems Date: Wed, 20 Apr 2022 08:18:13 +0200 Subject: [PATCH] Refactor to idempotent methods --- playbook.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/playbook.yml b/playbook.yml index 2342220..6d35051 100644 --- a/playbook.yml +++ b/playbook.yml @@ -66,9 +66,21 @@ groups: k3s_ha with_items: "{{ nodes }}" - - name: Store public keys in 'known_hosts' - ansible.builtin.command: - cmd: ssh-keyscan -t rsa {{ item.ip }} >> ~/.ssh/known_hosts + - name: Add new VM's as 'known_hosts' + block: + + - name: Scan public key + ansible.builtin.command: + cmd: "ssh-keyscan -t rsa {{ item.ip }}" + register: publickey + + - name: Store public key + ansible.builtin.known_hosts: + name: "{{ item.name }}" + key: "{{ publickey.stdout }}" + state: present + path: ~/.ssh/known_hosts + with_items: "{{ nodes }}" - name: Provision Kubernetes