Skip to content

Commit 898b48f

Browse files
committed
Added known_hosts support
1 parent 7042f21 commit 898b48f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ users:
4040
ssh_priv_key: 'path-to-id'
4141
ssh_authorized_keys:
4242
- path_to_key.pub
43+
ssh_known_hosts:
44+
- "[localhost]:2222 ecdsa-sha2-nistp256 soooomeeekey-here"
4345
gid: 1161
4446
uid: 2050
4547
disabled: no

tasks/ssh-keys.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,18 @@
2626
loop_control:
2727
loop_var: auth_key_path
2828
with_items: "{{ user.ssh_authorized_keys }}"
29+
30+
- when: "'ssh_known_hosts' in user and user.ssh_known_hosts"
31+
block:
32+
- name: Add host to known_hosts
33+
become_user: "{{ user.login }}"
34+
become: true
35+
lineinfile:
36+
path: "{{ user_home }}/.ssh/known_hosts"
37+
regexp: "^{{ known_host }}"
38+
line: "{{ known_host }}"
39+
create: true
40+
mode: 0600
41+
loop_control:
42+
loop_var: known_host
43+
with_items: "{{ user.ssh_known_hosts }}"

0 commit comments

Comments
 (0)