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.

62 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. notify: set secret_changed
  20. run_once: yes
  21. delegate_to: "{{groups['kube-master'][0]}}"
  22. when: gen_tokens|default(false)
  23. - name: Gen_tokens | generate tokens for node components
  24. command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item[0] }}-{{ item[1] }}"
  25. environment:
  26. TOKEN_DIR: "{{ kube_token_dir }}"
  27. with_nested:
  28. - [ 'system:kubelet' ]
  29. - "{{ groups['kube-node'] }}"
  30. register: gentoken_node
  31. changed_when: "'Added' in gentoken_node.stdout"
  32. notify: set secret_changed
  33. run_once: yes
  34. delegate_to: "{{groups['kube-master'][0]}}"
  35. when: gen_tokens|default(false)
  36. - name: Gen_tokens | Get list of tokens from first master
  37. shell: "(find {{ kube_token_dir }} -maxdepth 1 -type f)"
  38. register: tokens_list
  39. changed_when: false
  40. delegate_to: "{{groups['kube-master'][0]}}"
  41. when: sync_tokens|default(false)
  42. - name: Gen_tokens | Get the tokens from first master
  43. slurp:
  44. src: "{{ item }}"
  45. register: slurp_tokens
  46. with_items: '{{tokens_list.stdout_lines}}'
  47. run_once: true
  48. delegate_to: "{{groups['kube-master'][0]}}"
  49. when: sync_tokens|default(false)
  50. notify: set secret_changed
  51. - name: Gen_tokens | Copy tokens on masters
  52. copy:
  53. content: "{{ item.content|b64decode }}"
  54. dest: "{{ item.source }}"
  55. with_items: '{{slurp_tokens.results}}'
  56. when: inventory_hostname in groups['kube-master'] and sync_tokens|default(false) and
  57. inventory_hostname != groups['kube-master'][0]