mirror of
https://github.com/kubernetes-sigs/kubespray.git
synced 2026-08-07 13:21:46 -02:30
Testing for group membership with group names makes Kubespray more tolerant towards the structure of the inventory. Where 'inventory_hostname in groups["some_group"] would fail if "some_group" is not defined, '"some_group" in group_names' would not.
64 lines
2.1 KiB
YAML
64 lines
2.1 KiB
YAML
---
|
|
- name: Gen_tokens | copy tokens generation script
|
|
copy:
|
|
src: "kube-gen-token.sh"
|
|
dest: "{{ kube_script_dir }}/kube-gen-token.sh"
|
|
mode: "0700"
|
|
run_once: true
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
|
when: gen_tokens | default(false)
|
|
|
|
- name: Gen_tokens | generate tokens for control plane components
|
|
command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item[0] }}-{{ item[1] }}"
|
|
environment:
|
|
TOKEN_DIR: "{{ kube_token_dir }}"
|
|
with_nested:
|
|
- [ "system:kubectl" ]
|
|
- "{{ groups['kube_control_plane'] }}"
|
|
register: gentoken_control_plane
|
|
changed_when: "'Added' in gentoken_control_plane.stdout"
|
|
run_once: true
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
|
when: gen_tokens | default(false)
|
|
|
|
- name: Gen_tokens | generate tokens for node components
|
|
command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item[0] }}-{{ item[1] }}"
|
|
environment:
|
|
TOKEN_DIR: "{{ kube_token_dir }}"
|
|
with_nested:
|
|
- [ 'system:kubelet' ]
|
|
- "{{ groups['kube_node'] }}"
|
|
register: gentoken_node
|
|
changed_when: "'Added' in gentoken_node.stdout"
|
|
run_once: true
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
|
when: gen_tokens | default(false)
|
|
|
|
- name: Gen_tokens | Get list of tokens from first control plane node
|
|
command: "find {{ kube_token_dir }} -maxdepth 1 -type f"
|
|
register: tokens_list
|
|
check_mode: false
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
|
run_once: true
|
|
when: sync_tokens | default(false)
|
|
|
|
- name: Gen_tokens | Gather tokens
|
|
shell: "set -o pipefail && tar cfz - {{ tokens_list.stdout_lines | join(' ') }} | base64 --wrap=0"
|
|
args:
|
|
executable: /bin/bash
|
|
register: tokens_data
|
|
check_mode: false
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
|
run_once: true
|
|
when: sync_tokens | default(false)
|
|
|
|
- name: Gen_tokens | Copy tokens on control plane nodes
|
|
shell: "set -o pipefail && echo '{{ tokens_data.stdout | quote }}' | base64 -d | tar xz -C /"
|
|
args:
|
|
executable: /bin/bash
|
|
when:
|
|
- ('kube_control_plane' in group_names)
|
|
- sync_tokens | default(false)
|
|
- inventory_hostname != groups['kube_control_plane'][0]
|
|
- tokens_data.stdout
|