36 lines
1.2 KiB
YAML
36 lines
1.2 KiB
YAML
---
|
|
- hosts: control-plane
|
|
name: "Export token hash and IPPORT for node to join"
|
|
|
|
tasks:
|
|
- name: "Cluster token"
|
|
shell: kubeadm token list | cut -d ' ' -f1 | sed -n '2p'
|
|
register: K8S_TOKEN
|
|
|
|
- name: "CA Hash"
|
|
shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
|
|
register: K8S_MASTER_CA_HASH
|
|
|
|
- name: "IP and port"
|
|
shell: kubectl cluster-info | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | cut -d ' ' -f 7 | sed -n '1p' | cut -c 9-
|
|
register: K8S_IP_PORT
|
|
|
|
- name: "Add K8S Token and Hash to dummy host"
|
|
add_host:
|
|
name: "K8S_TOKEN_HOLDER"
|
|
token: "{{ K8S_TOKEN.stdout }}"
|
|
hash: "{{ K8S_MASTER_CA_HASH.stdout }}"
|
|
ipport: "{{ K8S_IP_PORT.stdout }}"
|
|
|
|
- name:
|
|
debug:
|
|
msg: "[Master] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}"
|
|
|
|
- name:
|
|
debug:
|
|
msg: "[Master] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}"
|
|
|
|
- name:
|
|
debug:
|
|
msg: "[Master] K8S_TOKEN_HOLDER K8S IP and port is {{ hostvars['K8S_TOKEN_HOLDER']['ipport'] }}"
|