main.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ---
  2. - name: Ensure CA certificate exists on openshift_ca_host
  3. stat:
  4. path: "{{ openshift_ca_cert }}"
  5. register: g_ca_cert_stat_result
  6. delegate_to: "{{ openshift_ca_host }}"
  7. run_once: true
  8. - fail:
  9. msg: >
  10. CA certificate {{ openshift_ca_cert }} doesn't exist on CA host
  11. {{ openshift_ca_host }}. Apply 'openshift_ca' role to
  12. {{ openshift_ca_host }}.
  13. when: not g_ca_cert_stat_result.stat.exists | bool
  14. run_once: true
  15. - name: Check status of node certificates
  16. stat:
  17. path: "{{ openshift.common.config_base }}/node/{{ item }}"
  18. with_items:
  19. - "system:node:{{ openshift.common.hostname }}.crt"
  20. - "system:node:{{ openshift.common.hostname }}.key"
  21. - "system:node:{{ openshift.common.hostname }}.kubeconfig"
  22. - ca.crt
  23. - server.key
  24. - server.crt
  25. register: g_node_cert_stat_result
  26. - set_fact:
  27. node_certs_missing: "{{ False in (g_node_cert_stat_result.results
  28. | oo_collect(attribute='stat.exists')
  29. | list) }}"
  30. - name: Create openshift_generated_configs_dir if it does not exist
  31. file:
  32. path: "{{ openshift_generated_configs_dir }}"
  33. state: directory
  34. mode: 0700
  35. when: node_certs_missing | bool
  36. delegate_to: "{{ openshift_ca_host }}"
  37. - name: Generate the node client config
  38. command: >
  39. {{ openshift.common.admin_binary }} create-api-client-config
  40. {% for named_ca_certificate in hostvars[openshift_ca_host].openshift.master.named_certificates | default([]) | oo_collect('cafile') %}
  41. --certificate-authority {{ named_ca_certificate }}
  42. {% endfor %}
  43. --certificate-authority={{ openshift_ca_cert }}
  44. --client-dir={{ openshift_node_generated_config_dir }}
  45. --groups=system:nodes
  46. --master={{ hostvars[openshift_ca_host].openshift.master.api_url }}
  47. --signer-cert={{ openshift_ca_cert }}
  48. --signer-key={{ openshift_ca_key }}
  49. --signer-serial={{ openshift_ca_serial }}
  50. --user=system:node:{{ openshift.common.hostname }}
  51. args:
  52. creates: "{{ openshift_node_generated_config_dir }}"
  53. when: node_certs_missing | bool
  54. delegate_to: "{{ openshift_ca_host }}"
  55. - name: Generate the node server certificate
  56. command: >
  57. {{ openshift.common.admin_binary }} ca create-server-cert
  58. --cert={{ openshift_node_generated_config_dir }}/server.crt
  59. --key={{ openshift_generated_configs_dir }}/node-{{ openshift.common.hostname }}/server.key
  60. --overwrite=true
  61. --hostnames={{ openshift.common.all_hostnames |join(",") }}
  62. --signer-cert={{ openshift_ca_cert }}
  63. --signer-key={{ openshift_ca_key }}
  64. --signer-serial={{ openshift_ca_serial }}
  65. args:
  66. creates: "{{ openshift_node_generated_config_dir }}/server.crt"
  67. when: node_certs_missing | bool
  68. delegate_to: "{{ openshift_ca_host}}"
  69. - name: Create local temp directory for syncing certs
  70. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  71. register: node_cert_mktemp
  72. changed_when: False
  73. when: node_certs_missing | bool
  74. delegate_to: localhost
  75. become: no
  76. - name: Create a tarball of the node config directories
  77. command: >
  78. tar -czvf {{ openshift_node_generated_config_dir }}.tgz
  79. --transform 's|system:{{ openshift_node_cert_subdir }}|node|'
  80. -C {{ openshift_node_generated_config_dir }} .
  81. args:
  82. creates: "{{ openshift_node_generated_config_dir }}.tgz"
  83. when: node_certs_missing | bool
  84. delegate_to: "{{ openshift_ca_host }}"
  85. - name: Retrieve the node config tarballs from the master
  86. fetch:
  87. src: "{{ openshift_node_generated_config_dir }}.tgz"
  88. dest: "{{ node_cert_mktemp.stdout }}/"
  89. flat: yes
  90. fail_on_missing: yes
  91. validate_checksum: yes
  92. when: node_certs_missing | bool
  93. delegate_to: "{{ openshift_ca_host }}"
  94. - name: Ensure certificate directory exists
  95. file:
  96. path: "{{ openshift_node_cert_dir }}"
  97. state: directory
  98. when: node_certs_missing | bool
  99. - name: Unarchive the tarball on the node
  100. unarchive:
  101. src: "{{ node_cert_mktemp.stdout }}/{{ openshift_node_cert_subdir }}.tgz"
  102. dest: "{{ openshift_node_cert_dir }}"
  103. when: node_certs_missing | bool
  104. - file: name={{ node_cert_mktemp.stdout }} state=absent
  105. changed_when: False
  106. when: node_certs_missing | bool
  107. delegate_to: localhost
  108. become: no