main.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ---
  2. - set_fact:
  3. openshift_master_certs_no_etcd:
  4. - admin.crt
  5. - master.kubelet-client.crt
  6. - "{{ 'master.proxy-client.crt' if openshift.common.version_gte_3_1_or_1_1 else omit }}"
  7. - master.server.crt
  8. - openshift-master.crt
  9. - openshift-registry.crt
  10. - openshift-router.crt
  11. - etcd.server.crt
  12. openshift_master_certs_etcd:
  13. - master.etcd-client.crt
  14. - set_fact:
  15. openshift_master_certs: "{{ (openshift_master_certs_no_etcd | union(openshift_master_certs_etcd )) if openshift_master_etcd_hosts | length > 0 else openshift_master_certs_no_etcd }}"
  16. - name: Check status of master certificates
  17. stat:
  18. path: "{{ openshift_master_config_dir }}/{{ item }}"
  19. with_items:
  20. - "{{ openshift_master_certs }}"
  21. register: g_master_cert_stat_result
  22. - set_fact:
  23. master_certs_missing: "{{ False in (g_master_cert_stat_result.results
  24. | oo_collect(attribute='stat.exists')
  25. | list) }}"
  26. - name: Ensure the generated_configs directory present
  27. file:
  28. path: "{{ openshift_master_generated_config_dir }}"
  29. state: directory
  30. mode: 0700
  31. when: master_certs_missing | bool
  32. delegate_to: "{{ openshift_ca_host }}"
  33. - file:
  34. src: "{{ openshift_master_config_dir }}/{{ item }}"
  35. dest: "{{ openshift_master_generated_config_dir }}/{{ item }}"
  36. state: hard
  37. with_items:
  38. - ca.crt
  39. - ca.key
  40. - ca.serial.txt
  41. when: master_certs_missing | bool
  42. delegate_to: "{{ openshift_ca_host }}"
  43. - name: Create the master certificates if they do not already exist
  44. command: >
  45. {{ openshift.common.admin_binary }} create-master-certs
  46. {% for named_ca_certificate in openshift.master.named_certificates | default([]) | oo_collect('cafile') %}
  47. --certificate-authority {{ named_ca_certificate }}
  48. {% endfor %}
  49. --hostnames={{ openshift.common.all_hostnames | join(',') }}
  50. --master={{ openshift.master.api_url }}
  51. --public-master={{ openshift.master.public_api_url }}
  52. --cert-dir={{ openshift_master_generated_config_dir }}
  53. --overwrite=false
  54. when: master_certs_missing | bool
  55. delegate_to: "{{ openshift_ca_host }}"
  56. - file:
  57. src: "{{ openshift_master_config_dir }}/{{ item }}"
  58. dest: "{{ openshift_master_generated_config_dir }}/{{ item }}"
  59. state: hard
  60. force: true
  61. with_items:
  62. - "{{ hostvars[inventory_hostname] | certificates_to_synchronize }}"
  63. when: master_certs_missing | bool
  64. delegate_to: "{{ openshift_ca_host }}"
  65. - name: Remove generated etcd client certs when using external etcd
  66. file:
  67. path: "{{ openshift_master_generated_config_dir }}/{{ item }}"
  68. state: absent
  69. when: openshift_master_etcd_hosts | length > 0
  70. with_items:
  71. - master.etcd-client.crt
  72. - master.etcd-client.key
  73. delegate_to: "{{ openshift_ca_host }}"
  74. - name: Create local temp directory for syncing certs
  75. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  76. register: g_master_mktemp
  77. changed_when: False
  78. when: master_certs_missing | bool
  79. delegate_to: localhost
  80. become: no
  81. - name: Create a tarball of the master certs
  82. command: >
  83. tar -czvf {{ openshift_master_generated_config_dir }}.tgz
  84. -C {{ openshift_master_generated_config_dir }} .
  85. args:
  86. creates: "{{ openshift_master_generated_config_dir }}.tgz"
  87. when: master_certs_missing | bool and inventory_hostname != openshift_ca_host
  88. delegate_to: "{{ openshift_ca_host }}"
  89. - name: Retrieve the master cert tarball from the master
  90. fetch:
  91. src: "{{ openshift_master_generated_config_dir }}.tgz"
  92. dest: "{{ g_master_mktemp.stdout }}/"
  93. flat: yes
  94. fail_on_missing: yes
  95. validate_checksum: yes
  96. when: master_certs_missing | bool and inventory_hostname != openshift_ca_host
  97. delegate_to: "{{ openshift_ca_host }}"
  98. - name: Ensure certificate directory exists
  99. file:
  100. path: "{{ openshift_master_config_dir }}"
  101. state: directory
  102. when: master_certs_missing | bool and inventory_hostname != openshift_ca_host
  103. - name: Unarchive the tarball on the master
  104. unarchive:
  105. src: "{{ g_master_mktemp.stdout }}/{{ openshift_master_cert_subdir }}.tgz"
  106. dest: "{{ openshift_master_config_dir }}"
  107. when: master_certs_missing | bool and inventory_hostname != openshift_ca_host
  108. - file: name={{ g_master_mktemp.stdout }} state=absent
  109. changed_when: False
  110. when: master_certs_missing | bool
  111. delegate_to: localhost
  112. become: no