main.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. --certificate-authority={{ openshift_ca_cert }}
  41. --client-dir={{ openshift_node_generated_config_dir }}
  42. --groups=system:nodes
  43. --master={{ hostvars[openshift_ca_host].openshift.master.api_url }}
  44. --signer-cert={{ openshift_ca_cert }}
  45. --signer-key={{ openshift_ca_key }}
  46. --signer-serial={{ openshift_ca_serial }}
  47. --user=system:node:{{ openshift.common.hostname }}
  48. args:
  49. creates: "{{ openshift_node_generated_config_dir }}"
  50. when: node_certs_missing | bool
  51. delegate_to: "{{ openshift_ca_host }}"
  52. - name: Generate the node server certificate
  53. command: >
  54. {{ openshift.common.admin_binary }} ca create-server-cert
  55. --cert={{ openshift_node_generated_config_dir }}/server.crt
  56. --key={{ openshift_generated_configs_dir }}/node-{{ openshift.common.hostname }}/server.key
  57. --overwrite=true
  58. --hostnames={{ openshift.common.all_hostnames |join(",") }}
  59. --signer-cert={{ openshift_ca_cert }}
  60. --signer-key={{ openshift_ca_key }}
  61. --signer-serial={{ openshift_ca_serial }}
  62. args:
  63. creates: "{{ openshift_node_generated_config_dir }}/server.crt"
  64. when: node_certs_missing | bool
  65. delegate_to: "{{ openshift_ca_host}}"
  66. - name: Create local temp directory for syncing certs
  67. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  68. register: node_cert_mktemp
  69. changed_when: False
  70. when: node_certs_missing | bool
  71. delegate_to: localhost
  72. become: no
  73. - name: Create a tarball of the node config directories
  74. command: >
  75. tar -czvf {{ openshift_node_generated_config_dir }}.tgz
  76. --transform 's|system:{{ openshift_node_cert_subdir }}|node|'
  77. -C {{ openshift_node_generated_config_dir }} .
  78. args:
  79. creates: "{{ openshift_node_generated_config_dir }}.tgz"
  80. when: node_certs_missing | bool
  81. delegate_to: "{{ openshift_ca_host }}"
  82. - name: Retrieve the node config tarballs from the master
  83. fetch:
  84. src: "{{ openshift_node_generated_config_dir }}.tgz"
  85. dest: "{{ node_cert_mktemp.stdout }}/"
  86. flat: yes
  87. fail_on_missing: yes
  88. validate_checksum: yes
  89. when: node_certs_missing | bool
  90. delegate_to: "{{ openshift_ca_host }}"
  91. - name: Ensure certificate directory exists
  92. file:
  93. path: "{{ openshift_node_cert_dir }}"
  94. state: directory
  95. when: node_certs_missing | bool
  96. - name: Unarchive the tarball on the node
  97. unarchive:
  98. src: "{{ node_cert_mktemp.stdout }}/{{ openshift_node_cert_subdir }}.tgz"
  99. dest: "{{ openshift_node_cert_dir }}"
  100. when: node_certs_missing | bool
  101. - file: name={{ node_cert_mktemp.stdout }} state=absent
  102. changed_when: False
  103. when: node_certs_missing | bool
  104. delegate_to: localhost
  105. become: no