-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_keys.yml
57 lines (57 loc) · 1.92 KB
/
install_keys.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
- hosts: all
gather_facts: no
tasks:
- name: Check whether key pair is present or not.
stat:
path: ./ssh_keys/kubeadm_test
register: key_pair_exists
delegate_to: 127.0.0.1
- name: Delete any previous k8s-hosts in the known_hosts file
lineinfile:
path: ~/.ssh/known_hosts
regexp: k8s-*
state: absent
delegate_to: 127.0.0.1
run_once: true
- name: Delete any previous kubeadm_test keys
file:
path: "./ssh_keys/{{ item }}"
state: absent
with_items:
- kubeadm_test
- kubeadm_test.pub
delegate_to: 127.0.0.1
run_once: true
when: not key_pair_exists.stat.exists
- name: Generate a new Random ssh key pair
command: ssh-keygen -f ./ssh_keys -t ed25519 -N '' -f ./ssh_keys/kubeadm_test
run_once: true
delegate_to: 127.0.0.1
register: keypair_generation_output
when: not key_pair_exists.stat.exists
- debug: var=keypair_generation_output
when: not key_pair_exists.stat.exists
- name: identify public key content on control machine
command: cat ./ssh_keys/kubeadm_test.pub
register: pub_key
run_once: true
delegate_to: 127.0.0.1
- debug: var=pub_key
- name: Transfer public key to guest machine
command: vagrant scp ssh_keys/kubeadm_test.pub .
run_once: true
delegate_to: 127.0.0.1
- name: Remove previous redundant ed_25119 keys
shell: vagrant ssh {{ inventory_hostname }} -c 'sed -i "/ssh-ed25519/d" ~/.ssh/authorized_keys'
delegate_to: 127.0.0.1
- name: put public key into the authorized_keys of the remote machines
shell: vagrant ssh {{ inventory_hostname }} -c 'cat kubeadm_test.pub >> ~/.ssh/authorized_keys'
delegate_to: 127.0.0.1
- name: Delete public keys
shell: vagrant ssh {{ inventory_hostname }} -c 'rm kubeadm_test.pub'
delegate_to: 127.0.0.1
- name: add ssh key to ssh agent
command: ssh-add ./ssh_keys/kubeadm_test
delegate_to: 127.0.0.1
run_once: true