File tree 4 files changed +48
-0
lines changed
4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -14,3 +14,10 @@ user_ansible:
14
14
groups : " "
15
15
# List of SSH pub keys to authorize. These must be provided as strings (content of the pub key).
16
16
ssh_keys : []
17
+ # List of SSH private keys to add to server. These must be provided as strings (content of the private key).
18
+ # Be sure to store securely using SOPS or similar.
19
+ ssh_private_keys : []
20
+ # List of hostnames to add to known_hosts.
21
+ known_hosts : []
22
+ # Whether or not to hash any provided hosts for known_hosts.
23
+ known_hosts_hash : true
Original file line number Diff line number Diff line change 44
44
with_items : " {{ user_ansible.ssh_keys }}"
45
45
loop_control :
46
46
loop_var : key
47
+
48
+ - name : Copy SSH private key to target.
49
+ ansible.builtin.copy :
50
+ dest : " /home/{{ user_ansible.username }}/.ssh/{% if key_id == 0 %}id_rsa{% else %}id_rsa_{{ key_id }}{% endif %}"
51
+ content : " {{ key }}"
52
+ owner : " {{ user_ansible.username }}"
53
+ group : " {{ user_ansible.username }}"
54
+ mode : ' 0600'
55
+ with_items : " {{ user_ansible.ssh_private_keys }}"
56
+ no_log : true
57
+ loop_control :
58
+ loop_var : key
59
+ index_var : key_id
60
+
61
+ - name : Ensure known_hosts file exists.
62
+ ansible.builtin.file :
63
+ path : " /home/{{ user_ansible.username }}/.ssh/known_hosts"
64
+ state : touch
65
+ owner : " {{ user_ansible.username }}"
66
+ group : " {{ user_ansible.username }}"
67
+ mode : ' 0600'
68
+ when : user_ansible.known_hosts | length
69
+
70
+ - name : Add public keys to known_hosts.
71
+ ansible.builtin.known_hosts :
72
+ hash_host : " {{ user_ansible.known_hosts_hash }}"
73
+ path : " /home/{{ user_ansible.username }}/.ssh/known_hosts"
74
+ name : " {{ host }}"
75
+ key : " {{ lookup('pipe', 'ssh-keyscan -t rsa ' + host) }}"
76
+ state : present
77
+ with_items : " {{ user_ansible.known_hosts }}"
78
+ loop_control :
79
+ loop_var : host
Original file line number Diff line number Diff line change @@ -14,3 +14,7 @@ user_deploy:
14
14
# List of additional groups to add the user to.
15
15
groups : []
16
16
ssh_keys : []
17
+ # If you add more than one key here, make sure the original private key of your deploy server is the first.
18
+ ssh_private_keys : []
19
+ known_hosts : []
20
+ known_hosts_hash : true
Original file line number Diff line number Diff line change @@ -12,3 +12,7 @@ user_provision:
12
12
sudoer : true
13
13
groups : []
14
14
ssh_keys : []
15
+ # If you add more than one key here, make sure the original private key of your infra controller server is the first.
16
+ ssh_private_keys : []
17
+ known_hosts : []
18
+ known_hosts_hash : true
You can’t perform that action at this time.
0 commit comments