kubespray/roles/kubernetes/tokens/tasks/gen_tokens.yml

64 lines
2.1 KiB
YAML
Raw Normal View History

---
- name: Gen_tokens | copy tokens generation script
2016-05-07 01:17:59 +08:00
copy:
src: "kube-gen-token.sh"
dest: "{{ kube_script_dir }}/kube-gen-token.sh"
mode: "0700"
2016-05-07 01:17:59 +08:00
run_once: yes
delegate_to: "{{ groups['kube_control_plane'][0] }}"
when: gen_tokens | default(false)
2016-05-07 01:17:59 +08:00
- name: Gen_tokens | generate tokens for master components
2016-05-07 01:17:59 +08:00
command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item[0] }}-{{ item[1] }}"
environment:
2016-05-07 01:17:59 +08:00
TOKEN_DIR: "{{ kube_token_dir }}"
with_nested:
- [ "system:kubectl" ]
- "{{ groups['kube_control_plane'] }}"
register: gentoken_master
changed_when: "'Added' in gentoken_master.stdout"
2016-05-07 01:17:59 +08:00
run_once: yes
delegate_to: "{{ groups['kube_control_plane'][0] }}"
when: gen_tokens | default(false)
- name: Gen_tokens | generate tokens for node components
2016-05-07 01:17:59 +08:00
command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item[0] }}-{{ item[1] }}"
environment:
2016-05-07 01:17:59 +08:00
TOKEN_DIR: "{{ kube_token_dir }}"
with_nested:
- [ 'system:kubelet' ]
- "{{ groups['kube_node'] }}"
register: gentoken_node
changed_when: "'Added' in gentoken_node.stdout"
2016-05-07 01:17:59 +08:00
run_once: yes
delegate_to: "{{ groups['kube_control_plane'][0] }}"
when: gen_tokens | default(false)
2016-05-07 01:17:59 +08:00
2020-07-28 16:39:08 +08:00
- name: Gen_tokens | Get list of tokens from first master
command: "find {{ kube_token_dir }} -maxdepth 1 -type f"
2016-05-07 01:17:59 +08:00
register: tokens_list
check_mode: no
delegate_to: "{{ groups['kube_control_plane'][0] }}"
run_once: true
when: sync_tokens | default(false)
2016-05-07 01:17:59 +08:00
2020-08-05 22:56:28 +08:00
- name: Gen_tokens | Gather tokens
shell: "set -o pipefail && tar cfz - {{ tokens_list.stdout_lines | join(' ') }} | base64 --wrap=0"
args:
2020-08-05 22:56:28 +08:00
executable: /bin/bash
register: tokens_data
check_mode: no
delegate_to: "{{ groups['kube_control_plane'][0] }}"
run_once: true
when: sync_tokens | default(false)
2020-08-05 22:56:28 +08:00
- name: Gen_tokens | Copy tokens on masters
shell: "set -o pipefail && echo '{{ tokens_data.stdout | quote }}' | base64 -d | tar xz -C /"
2020-08-05 22:56:28 +08:00
args:
executable: /bin/bash
when:
- inventory_hostname in groups['kube_control_plane']
- sync_tokens | default(false)
- inventory_hostname != groups['kube_control_plane'][0]
- tokens_data.stdout