From 7f20c64d44c6b47dcf3616fbcb3b5187a4782be3 Mon Sep 17 00:00:00 2001 From: Tony Kay Date: Thu, 26 Nov 2020 09:31:12 -0700 Subject: [PATCH] Ensure ssh setup works and is configured as the executing user and not root --- playbooks/dev.yml | 1 + .../files/{vagrant.private => vagrant.pem} | 0 .../tasks/main.yml | 52 ++++++++++--------- 3 files changed, 29 insertions(+), 24 deletions(-) rename roles/envy_manage_host_envy_configuration/files/{vagrant.private => vagrant.pem} (100%) diff --git a/playbooks/dev.yml b/playbooks/dev.yml index 367148c..8e643c6 100644 --- a/playbooks/dev.yml +++ b/playbooks/dev.yml @@ -6,6 +6,7 @@ vars: envy_name: default + envy_local_user: "{{ lookup('env', 'USER') }}" envy_default_domain: example.com # envy_default_image: rhel8-ssh envy_default_image: tonykay/centos-systemd-ssh diff --git a/roles/envy_manage_host_envy_configuration/files/vagrant.private b/roles/envy_manage_host_envy_configuration/files/vagrant.pem similarity index 100% rename from roles/envy_manage_host_envy_configuration/files/vagrant.private rename to roles/envy_manage_host_envy_configuration/files/vagrant.pem diff --git a/roles/envy_manage_host_envy_configuration/tasks/main.yml b/roles/envy_manage_host_envy_configuration/tasks/main.yml index 5dd4e9b..a2033fb 100644 --- a/roles/envy_manage_host_envy_configuration/tasks/main.yml +++ b/roles/envy_manage_host_envy_configuration/tasks/main.yml @@ -30,36 +30,40 @@ #- name: Copy ssh key to lab/ssh default to vagrant # copy: -# src: "{{ env_ssh_private_key | default('vagrant.private') }}" -# dest: "env-{{ envy_name }}/ssh/{{ env_ssh_private_key | default('vagrant.private') }}" -# dest: "{{ envy_home_directory }}/{{ env_ssh_private_key | default('vagrant.private') }}" +# src: "{{ env_ssh_private_key | default('vagrant.pem') }}" +# dest: "env-{{ envy_name }}/ssh/{{ env_ssh_private_key | default('vagrant.pem') }}" +# dest: "{{ envy_home_directory }}/{{ env_ssh_private_key | default('vagrant.pem') }}" # mode: 0400 # # SSH Config # -- name: Create user ssh Include config file - template: - src: ssh.cfg.j2 - dest: "~/.ssh/envy-{{ envy_name }}-config" - mode: "0644" - -- name: Ensure user ssh config files exists and add Include - lineinfile: - path: ~/.ssh/config - create: true - state: present - mode: "0644" - line: "Include envy-{{ envy_name }}-config" - insertbefore: BOF - -- name: "Copy ssh key to user .ssh default to vagrant" - copy: - src: "{{ env_ssh_private_key | default('vagrant.private') }}" - dest: "~/.ssh/{{ env_ssh_private_key | default('vagrant.private') }}" - mode: 0400 - +- name: "Setup the local {{ envy_local_user }} SSH configuration" + block: + + - name: Create user SSH Include config file + template: + src: ssh.cfg.j2 + dest: "~/.ssh/envy-{{ envy_name }}-config" + mode: "0644" + + - name: Ensure user SSH config files exists and add Include + lineinfile: + path: ~/.ssh/config + create: true + state: present + mode: "0644" + line: "Include envy-{{ envy_name }}-config" + insertbefore: BOF + + - name: "Copy SSH key to {{ envy_local_user }} .ssh default to vagrant" + copy: + src: "{{ env_ssh_private_key | default('vagrant.pem') }}" + dest: "~/.ssh/{{ env_ssh_private_key | default('vagrant.pem') }}" + mode: 0400 + + become_user: "{{ envy_local_user }}" # # Setup /etc/hosts