-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(preinstall_config): Add
preinstall_config_leave_my_keys_alone
…
…to allow for user's to completely mange SSH keys
- Loading branch information
1 parent
e019926
commit 4d57f46
Showing
4 changed files
with
62 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
--- | ||
home_assistant_user: homeassistant | ||
has_reserved_ip: false | ||
has_reserved_ip: false | ||
preinstall_config_leave_my_keys_alone: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
- name: Ensure ssh directory exists for current user on the control machine | ||
file: | ||
path: "{{ lookup('env','HOME') + '/.ssh' }}" | ||
mode: "0700" | ||
become: no | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Check if SSH keypair already exists | ||
stat: | ||
path: "{{ key_file }}" | ||
register: existing_ssh_key | ||
become: no | ||
delegate_to: localhost | ||
run_once: true | ||
loop: | ||
- "{{ lookup('env','HOME') + '/.ssh/id_rsa' }}" | ||
- "{{ lookup('env','HOME') + '/.ssh/id_rsa.pub' }}" | ||
loop_control: | ||
loop_var: key_file | ||
|
||
- name: Backup existing SSH private key if we need new keys | ||
copy: | ||
src: "{{ lookup('env','HOME') + '/.ssh/id_rsa' }}" | ||
dest: "{{ lookup('env','HOME') + '/.ssh/id_rsa.bak' }}" | ||
backup: yes | ||
mode: '0600' | ||
loop: "{{ existing_ssh_key.results }}" | ||
loop_control: | ||
loop_var: key_file | ||
when: key_file.stat.exists|bool | ||
become: no | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Create SSH key pair on the control machine to connect using home assistant user | ||
openssh_keypair: | ||
path: "{{ lookup('env','HOME') + '/.ssh/id_rsa' }}" | ||
comment: "homeassistant" | ||
when: >- | ||
not existing_ssh_key.results[0].stat.exists | bool | ||
or not existing_ssh_key.results[1].stat.exists | bool | ||
become: no | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Add public key to home assistant user authorized keys | ||
authorized_key: | ||
user: "{{ home_assistant_user }}" | ||
state: present | ||
key: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/id_rsa.pub') }}" |