From 59557b7f5719a9135486a4165b5c70a4d1b9e051 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Tue, 29 Mar 2016 15:25:32 -0400 Subject: [PATCH] Switch to templating for ssh files Change-Id: Ic86877e26d982e3ba978aec772ade5bee5890a12 Signed-off-by: Paul Belanger --- defaults/main.yaml | 9 ++++++--- tasks/config.yaml | 18 +++++++++--------- templates/id_rsa.j2 | 4 ++++ templates/id_rsa.pub.j2 | 4 ++++ templates/known_hosts.j2 | 4 ++++ 5 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 templates/id_rsa.j2 create mode 100644 templates/id_rsa.pub.j2 create mode 100644 templates/known_hosts.j2 diff --git a/defaults/main.yaml b/defaults/main.yaml index 9e1aff2..8a66572 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -17,10 +17,13 @@ ssh_user_home: "/home/{{ ssh_user_name }}" ssh_user_group: "{{ ssh_user_name }}" ssh_key_private_content: -ssh_key_private_filename: id_rsa +ssh_key_private_dest: "{{ ssh_user_home }}/.ssh/id_rsa" +ssh_key_private_src: id_rsa.j2 ssh_key_public_content: -ssh_key_public_filename: id_rsa.pub +ssh_key_public_dest: "{{ ssh_user_home }}/.ssh/id_rsa.pub" +ssh_key_public_src: id_rsa.pub.j2 ssh_known_hosts_content: -ssh_known_hosts_filename: known_hosts +ssh_known_hosts_dest: "{{ ssh_user_home }}/.ssh/known_hosts" +ssh_known_hosts_src: known_hosts.j2 diff --git a/tasks/config.yaml b/tasks/config.yaml index 6992632..beefaf0 100644 --- a/tasks/config.yaml +++ b/tasks/config.yaml @@ -21,28 +21,28 @@ state: directory - name: Create ssh known_hosts file. - copy: - content: "{{ ssh_known_hosts_content }}" - dest: "{{ ssh_user_home }}/.ssh/{{ ssh_known_hosts_filename }}" + template: + dest: "{{ ssh_known_hosts_dest }}" group: "{{ ssh_user_group }}" mode: 0644 owner: "{{ ssh_user_name }}" + src: "{{ ssh_known_hosts_src }}" when: ssh_known_hosts_content - name: Create ssh private key. - copy: - content: "{{ ssh_key_private_content }}" - dest: "{{ ssh_user_home }}/.ssh/{{ ssh_key_private_filename }}" + template: + dest: "{{ ssh_key_private_dest }}" group: "{{ ssh_user_group }}" mode: 0600 owner: "{{ ssh_user_name }}" + src: "{{ ssh_key_private_src }}" when: ssh_key_private_content - name: Create ssh public key. - copy: - content: "{{ ssh_key_public_content }}" - dest: "{{ ssh_user_home }}/.ssh/{{ ssh_key_public_filename }}" + template: + dest: "{{ ssh_key_public_dest }}" group: "{{ ssh_user_group }}" mode: 0644 owner: "{{ ssh_user_name }}" + src: "{{ ssh_key_public_src }}" when: ssh_key_public_content diff --git a/templates/id_rsa.j2 b/templates/id_rsa.j2 new file mode 100644 index 0000000..eeec098 --- /dev/null +++ b/templates/id_rsa.j2 @@ -0,0 +1,4 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# +{{ ssh_key_private_content }} diff --git a/templates/id_rsa.pub.j2 b/templates/id_rsa.pub.j2 new file mode 100644 index 0000000..116439b --- /dev/null +++ b/templates/id_rsa.pub.j2 @@ -0,0 +1,4 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# +{{ ssh_key_public_content }} diff --git a/templates/known_hosts.j2 b/templates/known_hosts.j2 new file mode 100644 index 0000000..c1c880c --- /dev/null +++ b/templates/known_hosts.j2 @@ -0,0 +1,4 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# +{{ ssh_known_hosts_content }}