generate_hawkular_certificates.yaml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ---
  2. - name: generate hawkular-metrics certificates
  3. include: setup_certificate.yaml
  4. vars:
  5. component: hawkular-metrics
  6. hostnames: "hawkular-metrics,hawkular-metrics.{{ openshift_metrics_project }}.svc.cluster.local,{{ openshift_metrics_hawkular_hostname }}"
  7. changed_when: no
  8. - name: generate hawkular-cassandra certificates
  9. include: setup_certificate.yaml
  10. vars:
  11. component: hawkular-cassandra
  12. hostnames: hawkular-cassandra
  13. changed_when: no
  14. - name: generate password for hawkular metrics
  15. local_action: copy dest="{{ local_tmp.stdout }}/{{ item }}.pwd" content="{{ 15 | oo_random_word }}"
  16. with_items:
  17. - hawkular-metrics
  18. become: false
  19. - local_action: slurp src="{{ local_tmp.stdout }}/hawkular-metrics.pwd"
  20. register: hawkular_metrics_pwd
  21. no_log: true
  22. become: false
  23. - name: generate htpasswd file for hawkular metrics
  24. local_action: htpasswd path="{{ local_tmp.stdout }}/hawkular-metrics.htpasswd" name=hawkular password="{{ hawkular_metrics_pwd.content | b64decode }}"
  25. become: false
  26. - name: copy local generated passwords to target
  27. copy:
  28. src: "{{ local_tmp.stdout }}/{{ item }}"
  29. dest: "{{ mktemp.stdout }}/{{ item }}"
  30. with_items:
  31. - hawkular-metrics.pwd
  32. - hawkular-metrics.htpasswd
  33. - name: read files for the hawkular-metrics secret
  34. shell: >
  35. printf '%s: ' '{{ item }}'
  36. && base64 --wrap 0 '{{ mktemp.stdout }}/{{ item }}'
  37. register: hawkular_secrets
  38. with_items:
  39. - ca.crt
  40. - hawkular-metrics.pwd
  41. - hawkular-metrics.htpasswd
  42. - hawkular-metrics.crt
  43. - hawkular-metrics.key
  44. - hawkular-metrics.pem
  45. - hawkular-cassandra.crt
  46. - hawkular-cassandra.key
  47. - hawkular-cassandra.pem
  48. changed_when: false
  49. - set_fact:
  50. hawkular_secrets: |
  51. {{ hawkular_secrets.results|map(attribute='stdout')|join('
  52. ')|from_yaml }}
  53. - name: generate hawkular-metrics-certs secret template
  54. template:
  55. src: secret.j2
  56. dest: "{{ mktemp.stdout }}/templates/hawkular-metrics-certs.yaml"
  57. vars:
  58. name: hawkular-metrics-certs
  59. labels:
  60. metrics-infra: hawkular-metrics-certs
  61. annotations:
  62. service.alpha.openshift.io/originating-service-name: hawkular-metrics
  63. data:
  64. tls.crt: >
  65. {{ hawkular_secrets['hawkular-metrics.crt'] }}
  66. tls.key: >
  67. {{ hawkular_secrets['hawkular-metrics.key'] }}
  68. tls.truststore.crt: >
  69. {{ hawkular_secrets['hawkular-cassandra.crt'] }}
  70. ca.crt: >
  71. {{ hawkular_secrets['ca.crt'] }}
  72. when: name not in metrics_secrets.stdout_lines
  73. changed_when: no
  74. - name: generate hawkular-metrics-account secret template
  75. template:
  76. src: secret.j2
  77. dest: "{{ mktemp.stdout }}/templates/hawkular_metrics_account.yaml"
  78. vars:
  79. name: hawkular-metrics-account
  80. labels:
  81. metrics-infra: hawkular-metrics
  82. data:
  83. hawkular-metrics.username: "{{ 'hawkular'|b64encode }}"
  84. hawkular-metrics.htpasswd: "{{ hawkular_secrets['hawkular-metrics.htpasswd'] }}"
  85. hawkular-metrics.password: >
  86. {{ hawkular_secrets['hawkular-metrics.pwd'] }}
  87. when: name not in metrics_secrets.stdout_lines
  88. changed_when: no
  89. - name: generate cassandra secret template
  90. template:
  91. src: secret.j2
  92. dest: "{{ mktemp.stdout }}/templates/hawkular-cassandra-certs.yaml"
  93. vars:
  94. name: hawkular-cassandra-certs
  95. labels:
  96. metrics-infra: hawkular-cassandra-certs
  97. annotations:
  98. service.alpha.openshift.io/originating-service-name: hawkular-cassandra
  99. data:
  100. tls.crt: >
  101. {{ hawkular_secrets['hawkular-cassandra.crt'] }}
  102. tls.key: >
  103. {{ hawkular_secrets['hawkular-cassandra.key'] }}
  104. tls.peer.truststore.crt: >
  105. {{ hawkular_secrets['hawkular-cassandra.crt'] }}
  106. tls.client.truststore.crt: >
  107. {{ hawkular_secrets['hawkular-metrics.crt'] }}
  108. when: name not in metrics_secrets
  109. changed_when: no