main.yml 3.3 KB

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