main.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. with_items:
  56. - src: "{{ (openshift_master_ca_certificate | default({'certfile':none})).certfile }}"
  57. dest: ca.crt
  58. - src: "{{ (openshift_master_ca_certificate | default({'keyfile':none})).keyfile }}"
  59. dest: ca.key
  60. when: openshift_master_ca_certificate is defined
  61. delegate_to: "{{ openshift_ca_host }}"
  62. run_once: true
  63. - name: Create ca serial
  64. copy:
  65. content: "00"
  66. dest: "{{ openshift_ca_config_dir }}/ca.serial.txt"
  67. force: "{{ openshift_certificates_redeploy | default(false) | bool }}"
  68. when: openshift_master_ca_certificate is defined
  69. delegate_to: "{{ openshift_ca_host }}"
  70. run_once: true
  71. - find:
  72. paths: "{{ openshift.common.config_base }}/master/legacy-ca/"
  73. patterns: ".*-ca.crt"
  74. use_regex: true
  75. register: g_master_legacy_ca_result
  76. # This should NOT replace the CA due to --overwrite=false when a CA already exists.
  77. - name: Create the master certificates if they do not already exist
  78. command: >
  79. {{ hostvars[openshift_ca_host].openshift.common.client_binary }} adm create-master-certs
  80. {% for named_ca_certificate in openshift.master.named_certificates | default([]) | oo_collect('cafile') %}
  81. --certificate-authority {{ named_ca_certificate }}
  82. {% endfor %}
  83. {% for legacy_ca_certificate in g_master_legacy_ca_result.files | default([]) | oo_collect('path') %}
  84. --certificate-authority {{ legacy_ca_certificate }}
  85. {% endfor %}
  86. --hostnames={{ openshift.common.all_hostnames | join(',') }}
  87. --master={{ openshift.master.api_url }}
  88. --public-master={{ openshift.master.public_api_url }}
  89. --cert-dir={{ openshift_ca_config_dir }}
  90. --overwrite=false
  91. when: master_ca_missing | bool or openshift_certificates_redeploy | default(false) | bool
  92. delegate_to: "{{ openshift_ca_host }}"
  93. run_once: true
  94. - name: Restore original serviceaccount keys
  95. copy:
  96. src: "{{ item }}.keep"
  97. dest: "{{ item }}"
  98. remote_src: true
  99. with_items:
  100. - "{{ openshift_ca_config_dir }}/serviceaccounts.private.key"
  101. - "{{ openshift_ca_config_dir }}/serviceaccounts.public.key"
  102. when: openshift_certificates_redeploy | default(false) | bool
  103. - name: Remove backup serviceaccount keys
  104. file:
  105. path: "{{ item }}.keep"
  106. state: absent
  107. with_items:
  108. - "{{ openshift_ca_config_dir }}/serviceaccounts.private.key"
  109. - "{{ openshift_ca_config_dir }}/serviceaccounts.public.key"
  110. when: openshift_certificates_redeploy | default(false) | bool