From 92c97463af0bf0cce8f74b6e6c98b7df12a0ca64 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Sat, 1 Apr 2017 09:24:17 +0100 Subject: [PATCH] Create an SSH key in test project playbook if none exists --- ansible/test-project.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ansible/test-project.yml b/ansible/test-project.yml index 481bd0830..8c0ee7b7c 100644 --- a/ansible/test-project.yml +++ b/ansible/test-project.yml @@ -15,11 +15,23 @@ ram: -1 secgroup_rules: -1 secgroups: -1 + test_ssh_private_key_path: "{{ ansible_env.PWD ~ '/.ssh/id_rsa' }}" + test_ssh_public_key_path: "{{ test_ssh_private_key_path ~ '.pub' }}" + test_ssh_key_type: rsa pre_tasks: + - name: Check whether an SSH key exists on the controller + stat: + path: "{{ test_ssh_private_key_path }}" + register: ssh_key_stat + + - name: Generate an SSH key on the controller + command: ssh-keygen -t {{ test_ssh_key_type }} -N '' -f {{ test_ssh_private_key_path }} + when: not ssh_key_stat.stat.exists + - name: Read the SSH public key on the controller slurp: - src: "{{ ansible_env.PWD ~ '/.ssh/id_rsa.pub' }}" + src: "{{ test_ssh_public_key_path }}" register: ssh_public_key roles: