main.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ---
  2. - name: Include OS specific variables.
  3. include_vars: "{{ ansible_os_family }}.yml"
  4. - name: Install packages
  5. include_tasks: "setup/{{ ansible_os_family }}.yml"
  6. - name: Get HAProxy version.
  7. command: haproxy -v
  8. register: haproxy_version_result
  9. changed_when: false
  10. check_mode: false
  11. - name: The HAProxy version.
  12. debug: var=haproxy_version_result.stdout
  13. - name: Set HAProxy version.
  14. set_fact:
  15. haproxy_version: '{{ haproxy_version_result.stdout_lines[0] | regex_replace("^HA-Proxy version ([0-9]\.[0-9]).*$", "\1") }}'
  16. - name: Get IP range.
  17. shell: "echo {{ network_allowed }} | cut -d'.' --fields=1,2,3"
  18. register: result
  19. - name: Get interface name.
  20. shell: "ip -4 addr show | grep {{ result.stdout }} | rev | cut -d ' ' -f 1 | rev"
  21. register: itfn
  22. - name: Set keepalived_bind_interface.
  23. set_fact:
  24. keepalived_bind_interface: "{{ itfn.stdout }}"
  25. - name: Integration net.ipv4
  26. blockinfile:
  27. dest: /etc/sysctl.conf
  28. block: |
  29. net.ipv4.ip_forward = 1
  30. net.ipv4.ip_nonlocal_bind = 1
  31. - name: Ensure keepalived is started and enabled on boot.
  32. service: name=keepalived state=started enabled=yes
  33. - name: Ensure keepalived conf is set
  34. template: >
  35. src=templates/keepalived.conf.j2
  36. dest=/etc/keepalived/keepalived.conf
  37. - name: Ensure HAProxy is started and enabled on boot.
  38. service: name=haproxy state=started enabled=yes
  39. - name: Create private key (RSA, 4096 bits)
  40. community.crypto.openssl_privatekey:
  41. path: "{{ ssl_crt_path }}/{{ ssl_name }}.key"
  42. when: ssl_self
  43. - name: Create certificate signing request (CSR) for self-signed certificate
  44. community.crypto.openssl_csr_pipe:
  45. privatekey_path: "{{ ssl_crt_path }}/{{ ssl_name }}.key"
  46. country_name: BE
  47. locality_name: Louvain-la-Neuve
  48. common_name: "{{ ssl_name }}"
  49. organization_name: UCLouvain
  50. organizational_unit_name: ELIC
  51. register: csr
  52. when: ssl_self
  53. - name: Generate a Self Signed OpenSSL certificate
  54. community.crypto.x509_certificate:
  55. path: "{{ ssl_crt_path }}/{{ ssl_name }}.crt"
  56. csr_content: "{{ csr.csr }}"
  57. privatekey_path: "{{ ssl_crt_path }}/{{ ssl_name }}.key"
  58. provider: selfsigned
  59. when: ssl_self
  60. - name: Merge KEY and CRT to generate PEM
  61. shell: "cat {{ ssl_crt_path }}/{{ ssl_name }}.key {{ ssl_crt_path }}/{{ ssl_name }}.crt >> {{ ssl_crt_path }}/{{ ssl_name }}.pem"
  62. when: ssl_self
  63. - name: Generate DH Parameters with a different size (2048 bits)
  64. community.crypto.openssl_dhparam:
  65. path: /etc/haproxy/dhparams.pem
  66. size: 2048
  67. #- name: Add ssl dhparam file
  68. # lineinfile:
  69. # path: /etc/haproxy/haproxy.cfg
  70. # insertafter: "^.*ssl-default-bind-options.*"
  71. # line: "\tssl-dh-param-file /etc/haproxy/dhparams.pem"
  72. # firstmatch: yes
  73. # state: present
  74. #
  75. #- name: Copy HAProxy configuration in place
  76. # set_fact:
  77. # cfg_content: "{{ lookup('template', '{{ role_path }}/templates/haproxy.cfg.j2') }}"
  78. #
  79. #- name: Merge HAProxy config file
  80. # blockinfile:
  81. # dest: "/etc/haproxy/haproxy.cfg"
  82. # content: '{{ cfg_content }}'
  83. # state: present
  84. - name: Ensure HAProxy conf is set
  85. template: >
  86. src=templates/haproxy.cfg.j2
  87. dest=/etc/haproxy/haproxy.cfg
  88. - name: keepalived restart
  89. service: name=keepalived state=restarted
  90. - name: HAProxy restart
  91. service: name=haproxy state=restarted