Skip to content

Commit

Permalink
Ensure ssh setup works and is configured as the executing user and no…
Browse files Browse the repository at this point in the history
…t root
  • Loading branch information
tonykay committed Nov 26, 2020
1 parent fdf1170 commit 7f20c64
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
1 change: 1 addition & 0 deletions playbooks/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 28 additions & 24 deletions roles/envy_manage_host_envy_configuration/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7f20c64

Please sign in to comment.