main.yml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ---
  2. - name: Get HAProxy version.
  3. command: haproxy -v
  4. register: haproxy_version_result
  5. changed_when: false
  6. check_mode: false
  7. - name: Set HAProxy version.
  8. set_fact:
  9. haproxy_version: '{{ haproxy_version_result.stdout_lines[0] | regex_replace("^HA-Proxy version ([0-9]\.[0-9]).*$", "\1") }}'
  10. - name: Ensure HAProxy is started and enabled on boot.
  11. service: name=haproxy state=started enabled=yes
  12. - name: Create private key (RSA, 4096 bits)
  13. community.crypto.openssl_privatekey:
  14. path: "{{ ssl_crt_path }}/{{ ssl_name }}.key"
  15. when: ssl_self
  16. - name: Create certificate signing request (CSR) for self-signed certificate
  17. community.crypto.openssl_csr_pipe:
  18. privatekey_path: "{{ ssl_crt_path }}/{{ ssl_name }}.key"
  19. country_name: BE
  20. locality_name: Louvain-la-Neuve
  21. common_name: "{{ ssl_name }}"
  22. organization_name: UCLouvain
  23. organizational_unit_name: ELIC
  24. register: csr
  25. when: ssl_self
  26. - name: Generate a Self Signed OpenSSL certificate
  27. community.crypto.x509_certificate:
  28. path: "{{ ssl_crt_path }}/{{ ssl_name }}.crt"
  29. csr_content: "{{ csr.csr }}"
  30. privatekey_path: "{{ ssl_crt_path }}/{{ ssl_name }}.key"
  31. provider: selfsigned
  32. when: ssl_self
  33. - name: Merge KEY and CRT to generate PEM
  34. shell: "cat {{ ssl_crt_path }}/{{ ssl_name }}.key {{ ssl_crt_path }}/{{ ssl_name }}.crt >> {{ ssl_crt_path }}/{{ ssl_name }}.pem"
  35. when: ssl_self
  36. - name: Generate DH Parameters with a different size (2048 bits)
  37. community.crypto.openssl_dhparam:
  38. path: /etc/haproxy/dhparams.pem
  39. size: 2048
  40. - name: Add ssl dhparam file
  41. lineinfile:
  42. path: /etc/haproxy/haproxy.cfg
  43. insertafter: "^.*ssl-default-bind-options.*"
  44. line: "\tssl-dh-param-file /etc/haproxy/dhparams.pem"
  45. firstmatch: yes
  46. state: present
  47. - name: Copy HAProxy configuration in place
  48. set_fact:
  49. cfg_content: "{{ lookup('template', '{{ role_path }}/templates/haproxy.cfg.j2') }}"
  50. - name: Merge HAProxy config file
  51. blockinfile:
  52. dest: "/etc/haproxy/haproxy.cfg"
  53. content: '{{ cfg_content }}'
  54. state: present
  55. - name: HAProxy restart
  56. service: name=haproxy state=restarted