main.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. ---
  2. - fail:
  3. msg: "openshift_ca_host variable must be defined for this role"
  4. when: openshift_ca_host is not defined
  5. - fail:
  6. msg: "Both 'certfile' and 'keyfile' keys must be supplied when configuring openshift_master_ca_certificate"
  7. when: openshift_master_ca_certificate is defined and ('certfile' not in openshift_master_ca_certificate or 'keyfile' not in openshift_master_ca_certificate)
  8. - name: Install the base package for admin tooling
  9. package:
  10. name: "{{ openshift.common.service_type }}{{ openshift_pkg_version | default('') | oo_image_tag_to_rpm_version(include_dash=True) }}"
  11. state: present
  12. when: not openshift.common.is_containerized | bool
  13. register: install_result
  14. delegate_to: "{{ openshift_ca_host }}"
  15. run_once: true
  16. - name: Reload generated facts
  17. openshift_facts:
  18. when: install_result | changed
  19. delegate_to: "{{ openshift_ca_host }}"
  20. run_once: true
  21. - name: Create openshift_ca_config_dir if it does not exist
  22. file:
  23. path: "{{ openshift_ca_config_dir }}"
  24. state: directory
  25. delegate_to: "{{ openshift_ca_host }}"
  26. run_once: true
  27. - name: Determine if CA must be created
  28. stat:
  29. path: "{{ openshift_ca_config_dir }}/{{ item }}"
  30. register: g_master_ca_stat_result
  31. with_items:
  32. - ca-bundle.crt
  33. - ca.crt
  34. - ca.key
  35. delegate_to: "{{ openshift_ca_host }}"
  36. run_once: true
  37. - set_fact:
  38. master_ca_missing: "{{ False in (g_master_ca_stat_result.results
  39. | oo_collect(attribute='stat.exists')
  40. | list) }}"
  41. run_once: true
  42. - name: Retain original serviceaccount keys
  43. copy:
  44. src: "{{ item }}"
  45. dest: "{{ item }}.keep"
  46. remote_src: true
  47. with_items:
  48. - "{{ openshift_ca_config_dir }}/serviceaccounts.private.key"
  49. - "{{ openshift_ca_config_dir }}/serviceaccounts.public.key"
  50. when: openshift_certificates_redeploy | default(false) | bool
  51. - name: Deploy master ca certificate
  52. copy:
  53. src: "{{ item.src }}"
  54. dest: "{{ openshift_ca_config_dir }}/{{ item.dest }}"
  55. force: no
  56. with_items:
  57. - src: "{{ (openshift_master_ca_certificate | default({'certfile':none})).certfile }}"
  58. dest: ca.crt
  59. - src: "{{ (openshift_master_ca_certificate | default({'keyfile':none})).keyfile }}"
  60. dest: ca.key
  61. when: openshift_master_ca_certificate is defined
  62. delegate_to: "{{ openshift_ca_host }}"
  63. run_once: true
  64. - name: Create ca serial
  65. copy:
  66. content: "00"
  67. dest: "{{ openshift_ca_config_dir }}/ca.serial.txt"
  68. force: "{{ openshift_certificates_redeploy | default(false) | bool }}"
  69. when: openshift_master_ca_certificate is defined
  70. delegate_to: "{{ openshift_ca_host }}"
  71. run_once: true
  72. - find:
  73. paths: "{{ openshift.common.config_base }}/master/legacy-ca/"
  74. patterns: ".*-ca.crt"
  75. use_regex: true
  76. register: g_master_legacy_ca_result
  77. # This should NOT replace the CA due to --overwrite=false when a CA already exists.
  78. - name: Create the master certificates if they do not already exist
  79. command: >
  80. {{ hostvars[openshift_ca_host].openshift.common.client_binary }} adm ca create-master-certs
  81. {% for named_ca_certificate in openshift.master.named_certificates | default([]) | oo_collect('cafile') %}
  82. --certificate-authority {{ named_ca_certificate }}
  83. {% endfor %}
  84. {% for legacy_ca_certificate in g_master_legacy_ca_result.files | default([]) | oo_collect('path') %}
  85. --certificate-authority {{ legacy_ca_certificate }}
  86. {% endfor %}
  87. --hostnames={{ hostvars[openshift_ca_host].openshift.common.all_hostnames | join(',') }}
  88. --master={{ openshift.master.api_url }}
  89. --public-master={{ openshift.master.public_api_url }}
  90. --cert-dir={{ openshift_ca_config_dir }}
  91. {% if openshift_version | oo_version_gte_3_5_or_1_5(openshift.common.deployment_type) | bool %}
  92. --expire-days={{ openshift_master_cert_expire_days }}
  93. --signer-expire-days={{ openshift_ca_cert_expire_days }}
  94. {% endif %}
  95. --overwrite=false
  96. when: master_ca_missing | bool or openshift_certificates_redeploy | default(false) | bool
  97. delegate_to: "{{ openshift_ca_host }}"
  98. run_once: true
  99. - name: Test local loopback context
  100. command: >
  101. {{ hostvars[openshift_ca_host].openshift.common.client_binary }} config view
  102. --config={{ openshift_master_loopback_config }}
  103. changed_when: false
  104. register: loopback_config
  105. delegate_to: "{{ openshift_ca_host }}"
  106. run_once: true
  107. - name: Generate the loopback master client config
  108. command: >
  109. {{ hostvars[openshift_ca_host].openshift.common.client_binary }} adm create-api-client-config
  110. {% for named_ca_certificate in openshift.master.named_certificates | default([]) | oo_collect('cafile') %}
  111. --certificate-authority {{ named_ca_certificate }}
  112. {% endfor %}
  113. --certificate-authority={{ openshift_ca_cert }}
  114. --client-dir={{ openshift_ca_config_dir }}
  115. --groups=system:masters,system:openshift-master
  116. --master={{ hostvars[openshift_ca_host].openshift.master.loopback_api_url }}
  117. --public-master={{ hostvars[openshift_ca_host].openshift.master.loopback_api_url }}
  118. --signer-cert={{ openshift_ca_cert }}
  119. --signer-key={{ openshift_ca_key }}
  120. --signer-serial={{ openshift_ca_serial }}
  121. --user=system:openshift-master
  122. --basename=openshift-master
  123. {% if openshift_version | oo_version_gte_3_5_or_1_5(openshift.common.deployment_type) | bool %}
  124. --expire-days={{ openshift_master_cert_expire_days }}
  125. {% endif %}
  126. when: loopback_context_string not in loopback_config.stdout
  127. delegate_to: "{{ openshift_ca_host }}"
  128. run_once: true
  129. - name: Restore original serviceaccount keys
  130. copy:
  131. src: "{{ item }}.keep"
  132. dest: "{{ item }}"
  133. remote_src: true
  134. with_items:
  135. - "{{ openshift_ca_config_dir }}/serviceaccounts.private.key"
  136. - "{{ openshift_ca_config_dir }}/serviceaccounts.public.key"
  137. when: openshift_certificates_redeploy | default(false) | bool
  138. - name: Remove backup serviceaccount keys
  139. file:
  140. path: "{{ item }}.keep"
  141. state: absent
  142. with_items:
  143. - "{{ openshift_ca_config_dir }}/serviceaccounts.private.key"
  144. - "{{ openshift_ca_config_dir }}/serviceaccounts.public.key"
  145. when: openshift_certificates_redeploy | default(false) | bool