main.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. --hostnames={{ openshift.common.all_hostnames | join(',') }}
  47. --master={{ openshift.master.api_url }}
  48. --public-master={{ openshift.master.public_api_url }}
  49. --cert-dir={{ openshift_master_generated_config_dir }}
  50. --overwrite=false
  51. when: master_certs_missing | bool
  52. delegate_to: "{{ openshift_ca_host }}"
  53. - file:
  54. src: "{{ openshift_master_config_dir }}/{{ item }}"
  55. dest: "{{ openshift_master_generated_config_dir }}/{{ item }}"
  56. state: hard
  57. force: true
  58. with_items:
  59. - "{{ hostvars[inventory_hostname] | certificates_to_synchronize }}"
  60. when: master_certs_missing | bool
  61. delegate_to: "{{ openshift_ca_host }}"
  62. - name: Remove generated etcd client certs when using external etcd
  63. file:
  64. path: "{{ openshift_master_generated_config_dir }}/{{ item }}"
  65. state: absent
  66. when: openshift_master_etcd_hosts | length > 0
  67. with_items:
  68. - master.etcd-client.crt
  69. - master.etcd-client.key
  70. delegate_to: "{{ openshift_ca_host }}"
  71. - name: Create local temp directory for syncing certs
  72. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  73. register: g_master_mktemp
  74. changed_when: False
  75. when: master_certs_missing | bool
  76. delegate_to: localhost
  77. become: no
  78. - name: Create a tarball of the master certs
  79. command: >
  80. tar -czvf {{ openshift_master_generated_config_dir }}.tgz
  81. -C {{ openshift_master_generated_config_dir }} .
  82. args:
  83. creates: "{{ openshift_master_generated_config_dir }}.tgz"
  84. when: master_certs_missing | bool and inventory_hostname != openshift_ca_host
  85. delegate_to: "{{ openshift_ca_host }}"
  86. - name: Retrieve the master cert tarball from the master
  87. fetch:
  88. src: "{{ openshift_master_generated_config_dir }}.tgz"
  89. dest: "{{ g_master_mktemp.stdout }}/"
  90. flat: yes
  91. fail_on_missing: yes
  92. validate_checksum: yes
  93. when: master_certs_missing | bool and inventory_hostname != openshift_ca_host
  94. delegate_to: "{{ openshift_ca_host }}"
  95. - name: Ensure certificate directory exists
  96. file:
  97. path: "{{ openshift_master_config_dir }}"
  98. state: directory
  99. when: master_certs_missing | bool and inventory_hostname != openshift_ca_host
  100. - name: Unarchive the tarball on the master
  101. unarchive:
  102. src: "{{ g_master_mktemp.stdout }}/{{ openshift_master_cert_subdir }}.tgz"
  103. dest: "{{ openshift_master_config_dir }}"
  104. when: master_certs_missing | bool and inventory_hostname != openshift_ca_host
  105. - file: name={{ g_master_mktemp.stdout }} state=absent
  106. changed_when: False
  107. when: master_certs_missing | bool
  108. delegate_to: localhost
  109. become: no