procure_server_certs.yaml 2.7 KB

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