procure_server_certs.yaml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ---
  2. - name: Checking for {{ cert_info.procure_component }}.crt
  3. stat:
  4. path: "{{generated_certs_dir}}/{{ cert_info.procure_component }}.crt"
  5. get_checksum: false
  6. get_attributes: false
  7. get_mime: false
  8. register: component_cert_file
  9. check_mode: no
  10. - name: Checking for {{ cert_info.procure_component }}.key
  11. stat:
  12. path: "{{generated_certs_dir}}/{{ cert_info.procure_component }}.key"
  13. get_checksum: false
  14. get_attributes: false
  15. get_mime: false
  16. register: component_key_file
  17. check_mode: no
  18. - name: Trying to discover server cert variable name for {{ cert_info.procure_component }}
  19. set_fact: procure_component_crt={{ lookup('env', '{{cert_info.procure_component}}' + '_crt') }}
  20. when:
  21. - cert_info.hostnames is undefined
  22. - cert_info[ cert_info.procure_component + '_crt' ] is defined
  23. - cert_info[ cert_info.procure_component + '_key' ] is defined
  24. check_mode: no
  25. - name: Trying to discover the server key variable name for {{ cert_info.procure_component }}
  26. set_fact: procure_component_key={{ lookup('env', '{{cert_info.procure_component}}' + '_key') }}
  27. when:
  28. - cert_info.hostnames is undefined
  29. - cert_info[ cert_info.procure_component + '_crt' ] is defined
  30. - cert_info[ cert_info.procure_component + '_key' ] is defined
  31. check_mode: no
  32. - name: Creating signed server cert and key for {{ cert_info.procure_component }}
  33. command: >
  34. {{ openshift_client_binary }} adm --config={{ mktemp.stdout }}/admin.kubeconfig ca create-server-cert
  35. --key={{generated_certs_dir}}/{{cert_info.procure_component}}.key --cert={{generated_certs_dir}}/{{cert_info.procure_component}}.crt
  36. --hostnames={{cert_info.hostnames|quote}} --signer-cert={{generated_certs_dir}}/ca.crt --signer-key={{generated_certs_dir}}/ca.key
  37. --signer-serial={{generated_certs_dir}}/ca.serial.txt
  38. check_mode: no
  39. when:
  40. - cert_info.hostnames is defined
  41. - not component_key_file.stat.exists
  42. - not component_cert_file.stat.exists
  43. - name: Copying server key for {{ cert_info.procure_component }} to generated certs directory
  44. copy: content="{{procure_component_key}}" dest={{generated_certs_dir}}/{{cert_info.procure_component}}.key
  45. check_mode: no
  46. when:
  47. - cert_info.hostnames is undefined
  48. - cert_info[ cert_info.procure_component + '_crt' ] is defined
  49. - cert_info[ cert_info.procure_component + '_key' ] is defined
  50. - not component_key_file.stat.exists
  51. - not component_cert_file.stat.exists
  52. - name: Copying Server cert for {{ cert_info.procure_component }} to generated certs directory
  53. copy: content="{{procure_component_crt}}" dest={{generated_certs_dir}}/{{cert_info.procure_component}}.crt
  54. check_mode: no
  55. when:
  56. - cert_info.hostnames is undefined
  57. - cert_info[ cert_info.procure_component + '_crt' ] is defined
  58. - cert_info[ cert_info.procure_component + '_key' ] is defined
  59. - not component_key_file.stat.exists
  60. - not component_cert_file.stat.exists