From e015807e729686dafc9ed6f9f81a0705d80705ff Mon Sep 17 00:00:00 2001 From: Kevin Fenzi Date: Thu, 28 May 2015 19:58:02 +0000 Subject: [PATCH] Add the same logic as for virt hosts to cloud spin up. When new instance is made it gathers the key automatically. --- tasks/persistent_cloud_new.yml | 14 ++++++++++++++ tasks/transient_cloud.yml | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tasks/persistent_cloud_new.yml b/tasks/persistent_cloud_new.yml index 3ffc457ea0..ab313357dc 100644 --- a/tasks/persistent_cloud_new.yml +++ b/tasks/persistent_cloud_new.yml @@ -44,6 +44,20 @@ local_action: wait_for host={{ public_ip }} port=22 delay=1 timeout=600 when: host_is_up|failed +- name: gather ssh host key from new instance + local_action: command ssh-keyscan -t rsa {{ inventory_hostname }} + ignore_errors: True + register: hostkey + when: host_is_up|failed + +- 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: host_is_up|failed + # SSH is up and running, however cloud-init still did not deployed ssh keypair # we have to wait some time. 10 sec is usually enough, but not always. - name: waiting for cloud-init diff --git a/tasks/transient_cloud.yml b/tasks/transient_cloud.yml index 69478a9b36..e432423a1a 100644 --- a/tasks/transient_cloud.yml +++ b/tasks/transient_cloud.yml @@ -36,6 +36,18 @@ - name: wait for he host to be hot local_action: wait_for host={{ nova_result.public_ip }} port=22 delay=1 timeout=600 +- name: gather ssh host key from new instance + local_action: command ssh-keyscan -t rsa {{ nova_result.public_ip }} + ignore_errors: True + register: hostkey + +- 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={{ nova_result.public_ip }} state=present + ignore_errors: True + with_items: + - /root/.ssh/known_hosts + - /etc/ssh/ssh_known_hosts + # SSH is up and running, however cloud-init still did not deployed ssh keypair # we have to wait some time. 10 sec is usually enough, but not always. - name: waiting for cloud-init