Add local private key guard 96/116496/3
authorPawel Wieczorek <p.wieczorek2@samsung.com>
Mon, 21 Dec 2020 10:23:31 +0000 (11:23 +0100)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Thu, 7 Jan 2021 10:34:50 +0000 (10:34 +0000)
Private key can be retrieved from OpenStack during keypair creation
only. Subsequent attempts to do so will result in getting an empty
string. If private key already exists on the local machine and there is
no guard local private key will be overwritten with an empty file.

This patch adds local private key guard which allows subsequent runs of
"create.yml" playbook without erasing local private key.

Issue-ID: INT-1601
Change-Id: If3b3bb088bc8a2f9494e21e1826ac68adcc7a2cb
Signed-off-by: Pawel Wieczorek <p.wieczorek2@samsung.com>
deployment/noheat/infra-openstack/ansible/roles/openstack/create_devstack_keypair/tasks/main.yml

index 4ac8a48..a330875 100644 (file)
     dest: "~/.ssh/{{ keypair.key.name }}.pub"
     mode: 0600
 
+- name: Check if local private key exists
+  stat:
+    path: "~/.ssh/{{ keypair.key.name }}"
+  register: local_private_key
+
 - name: Create local private key
   local_action:
     module: copy
     content: "{{ keypair.key.private_key }}"
     dest: "~/.ssh/{{ keypair.key.name }}"
     mode: 0600
+  when: local_private_key.stat.exists == False