From c1bb97974bb1f744ce5c51c915cadabf4ee493ac Mon Sep 17 00:00:00 2001 From: Kevin Fenzi Date: Thu, 28 May 2015 17:35:25 +0000 Subject: [PATCH] This is an attempt to gather initial ssh_host_key from new vms when they are made. This avoids having to accept the key manually and allows playbooks making new instances to complete without human intervention. (If it works as desired) --- tasks/virt_instance_create.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tasks/virt_instance_create.yml b/tasks/virt_instance_create.yml index 1d159fa95f..cf9055a7fd 100644 --- a/tasks/virt_instance_create.yml +++ b/tasks/virt_instance_create.yml @@ -48,3 +48,18 @@ - name: wait for ssh on the vm to start back local_action: wait_for delay=10 host={{ inventory_hostname }} port=22 state=started timeout=1200 when: inventory_hostname not in result.list_vms + +- name: gather ssh host key from new instance + local_action: ssh-keyscan -t rsa {{ inventory_hostname }} + ignore_errors: True + register: hostkey + when: inventory_hostname not in result.list_vms + +- name: add new ssh host key (you still need to add it to official ssh_host_keys later) + local_action: known_hosts path={{item}} key={{ hostkey.stdout }} host={{ inventory_hostname }} state=present + ignore_errors: True + with_items: + - /root/.ssh/known_hosts + - /etc/ssh/ssh_known_hosts + when: inventory_hostname not in result.list_vms +