You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.0 KiB

  1. ---
  2. - name: Gen_tokens | copy tokens generation script
  3. copy:
  4. src: "kube-gen-token.sh"
  5. dest: "{{ kube_script_dir }}/kube-gen-token.sh"
  6. mode: 0700
  7. run_once: yes
  8. delegate_to: "{{ groups['kube-master'][0] }}"
  9. when: gen_tokens|default(false)
  10. - name: Gen_tokens | generate tokens for master components
  11. command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item[0] }}-{{ item[1] }}"
  12. environment:
  13. TOKEN_DIR: "{{ kube_token_dir }}"
  14. with_nested:
  15. - [ "system:kubectl" ]
  16. - "{{ groups['kube-master'] }}"
  17. register: gentoken_master
  18. changed_when: "'Added' in gentoken_master.stdout"
  19. run_once: yes
  20. delegate_to: "{{ groups['kube-master'][0] }}"
  21. when: gen_tokens|default(false)
  22. - name: Gen_tokens | generate tokens for node components
  23. command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item[0] }}-{{ item[1] }}"
  24. environment:
  25. TOKEN_DIR: "{{ kube_token_dir }}"
  26. with_nested:
  27. - [ 'system:kubelet' ]
  28. - "{{ groups['kube-node'] }}"
  29. register: gentoken_node
  30. changed_when: "'Added' in gentoken_node.stdout"
  31. run_once: yes
  32. delegate_to: "{{ groups['kube-master'][0] }}"
  33. when: gen_tokens|default(false)
  34. - name: Gen_tokens | Get list of tokens from first master
  35. command: "find {{ kube_token_dir }} -maxdepth 1 -type f"
  36. register: tokens_list
  37. check_mode: no
  38. delegate_to: "{{ groups['kube-master'][0] }}"
  39. run_once: true
  40. when: sync_tokens|default(false)
  41. - name: Gen_tokens | Gather tokens
  42. shell: "set -o pipefail && tar cfz - {{ tokens_list.stdout_lines | join(' ') }} | base64 --wrap=0"
  43. args:
  44. warn: false
  45. executable: /bin/bash
  46. register: tokens_data
  47. check_mode: no
  48. delegate_to: "{{ groups['kube-master'][0] }}"
  49. run_once: true
  50. when: sync_tokens|default(false)
  51. - name: Gen_tokens | Copy tokens on masters
  52. shell: "set -o pipefail && echo '{{ tokens_data.stdout|quote }}' | base64 -d | tar xz -C /"
  53. args:
  54. executable: /bin/bash
  55. when:
  56. - inventory_hostname in groups['kube-master']
  57. - sync_tokens|default(false)
  58. - inventory_hostname != groups['kube-master'][0]
  59. - tokens_data.stdout