main.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ---
  2. - name: Calico | Run kube proxy
  3. run_once: true
  4. import_role:
  5. name: kube_proxy_and_dns
  6. - include_tasks: certs.yml
  7. - name: Calico | Clean Calico etcd data
  8. when: calico_cleanup_path is defined and calico_cleanup_path != ""
  9. file:
  10. state: absent
  11. path: "{{ calico_cleanup_path }}"
  12. - name: Calico | oc adm policy add-scc-to-user privileged system:serviceaccount:kube-system:calico-node
  13. oc_adm_policy_user:
  14. user: system:serviceaccount:kube-system:calico-node
  15. resource_kind: scc
  16. resource_name: privileged
  17. state: present
  18. - name: Calico | oc adm policy add-scc-to-user privileged system:serviceaccount:kube-system:calico-kube-controllers
  19. oc_adm_policy_user:
  20. user: system:serviceaccount:kube-system:calico-kube-controllers
  21. resource_kind: scc
  22. resource_name: privileged
  23. state: present
  24. - name: Calico | oc adm policy add-scc-to-user privileged system:serviceaccount:kube-system:calico-upgrade-job
  25. oc_adm_policy_user:
  26. user: system:serviceaccount:kube-system:calico-upgrade-job
  27. resource_kind: scc
  28. resource_name: privileged
  29. state: present
  30. - name: Calico | Set default selector for kube-system
  31. command: >
  32. {{ openshift_client_binary }}
  33. --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  34. annotate ns kube-system openshift.io/node-selector="" --overwrite
  35. - name: Calico | Create temp directory
  36. command: mktemp -d /tmp/openshift-ansible-XXXXXXX
  37. register: mktemp
  38. changed_when: False
  39. - name: Calico | Write separate Calico etcd manifest
  40. when: use_calico_etcd
  41. template:
  42. dest: "{{ mktemp.stdout }}/calico-etcd.yml"
  43. src: calico-etcd.yml.j2
  44. - name: Calico | Launch separate Calico etcd
  45. when: use_calico_etcd
  46. command: >
  47. {{ openshift_client_binary }} apply
  48. -f {{ mktemp.stdout }}/calico-etcd.yml
  49. --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  50. register: calico_etcd_create_output
  51. failed_when: "calico_etcd_create_output.rc != 0"
  52. changed_when: "('created' in calico_etcd_create_output.stdout) or ('configured' in calico_etcd_create_output.stdout)"
  53. - name: Calico | Parse node version
  54. set_fact:
  55. node_version: "{{ calico_node_image | regex_replace('^.*node:v?(.*)$', '\\1') }}"
  56. cnx: "{{ calico_node_image | regex_replace('^.*/(.*)-node:.*$', '\\1') }}"
  57. use_calico_credentials: "{{ calico_image_credentials is defined | bool }}"
  58. - name: Calico | Encode Docker Credentials
  59. shell: >
  60. cat {{ calico_image_credentials }} | openssl base64 -A
  61. register: calico_encoded_credentials_output
  62. failed_when: "calico_encoded_credentials_output.rc != 0 or calico_encoded_credentials_output.stdout == ''"
  63. when: use_calico_credentials
  64. - name: Calico | Set Encoded Docker Credentials Fact
  65. set_fact:
  66. calico_encoded_credentials: "{{ calico_encoded_credentials_output.stdout }}"
  67. when: use_calico_credentials
  68. - name: Calico | Write Calico Pull Secret
  69. template:
  70. dest: "{{ mktemp.stdout }}/calico-pull-secret.yml"
  71. src: calico-pull-secret.yml.j2
  72. when: use_calico_credentials
  73. - name: Calico | Create Calico Pull Secret
  74. when: use_calico_credentials
  75. command: >
  76. {{ openshift_client_binary }} apply
  77. -f {{ mktemp.stdout }}/calico-pull-secret.yml
  78. --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  79. register: calico_pull_secret_create_output
  80. failed_when: "calico_pull_secret_create_output.rc != 0"
  81. changed_when: "('created' in calico_pull_secret_create_output.stdout) or ('configured' in calico_pull_secret_create_output.stdout)"
  82. - name: Calico | Set the correct liveness and readiness checks
  83. set_fact:
  84. calico_binary_checks: "{{ (node_version > '3.2.0' and cnx != 'cnx') or (node_version > '2.2.0' and cnx == 'cnx') | bool }}"
  85. - name: Calico | Write Calico v2
  86. template:
  87. dest: "{{ mktemp.stdout }}/calico.yml"
  88. src: calico.yml.j2
  89. when:
  90. - node_version | regex_search('^[0-9]\.[0-9]\.[0-9]') and node_version < '3.0.0'
  91. - cnx != "cnx"
  92. - name: Calico | Write Calico v3
  93. template:
  94. dest: "{{ mktemp.stdout }}/calico.yml"
  95. src: calicov3.yml.j2
  96. when: (node_version | regex_search('^[0-9]\.[0-9]\.[0-9]') and node_version >= '3.0.0') or (node_version == 'master') or (cnx == "cnx" and node_version >= '2.0.0')
  97. - name: Calico | Launch Calico
  98. run_once: true
  99. command: >
  100. {{ openshift_client_binary }} apply
  101. -f {{ mktemp.stdout }}/calico.yml
  102. --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  103. register: calico_create_output
  104. failed_when: "calico_create_output.rc != 0"
  105. changed_when: "('created' in calico_create_output.stdout) or ('configured' in calico_create_output.stdout)"
  106. - name: Calico | Delete temp directory
  107. file:
  108. name: "{{ mktemp.stdout }}"
  109. state: absent
  110. changed_when: False