main.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ---
  2. - name: Set haproxy_backend_servers variable
  3. block:
  4. - name: Try group web_servers
  5. set_fact:
  6. haproxy_backend_servers: "{{ groups['web_servers'] | list }}"
  7. rescue:
  8. - name: Try group test_servers
  9. set_fact:
  10. haproxy_backend_servers: "{{ groups['test_servers'] | list }}"
  11. - name: Include OS specific variables.
  12. include_vars: "{{ ansible_os_family }}.yml"
  13. - name: Install packages
  14. include_tasks: "setup/{{ ansible_os_family }}.yml"
  15. - name: Get HAProxy version.
  16. command: haproxy -v
  17. register: haproxy_version_result
  18. changed_when: false
  19. check_mode: false
  20. - name: The HAProxy version.
  21. debug: var=haproxy_version_result.stdout
  22. - name: Set HAProxy version.
  23. set_fact:
  24. haproxy_version: '{{ haproxy_version_result.stdout_lines[0] | regex_replace("^HA-Proxy version ([0-9]\.[0-9]).*$", "\1") }}'
  25. - name: Get IP range.
  26. shell: "echo {{ network_allowed }} | cut -d'.' --fields=1,2,3"
  27. register: result
  28. - name: Get interface name.
  29. shell: "ip -4 addr show | grep {{ result.stdout }} | rev | cut -d ' ' -f 1 | rev"
  30. register: itfn
  31. - name: Integration net.ipv4
  32. blockinfile:
  33. dest: /etc/sysctl.conf
  34. block: |
  35. net.ipv4.ip_forward = 1
  36. net.ipv4.ip_nonlocal_bind = 1
  37. - name: Ensure HAProxy is enabled on boot
  38. service: name=haproxy 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. when: ssl_self
  68. #- name: Add ssl dhparam file
  69. # lineinfile:
  70. # path: /etc/haproxy/haproxy.cfg
  71. # insertafter: "^.*ssl-default-bind-options.*"
  72. # line: "\tssl-dh-param-file /etc/haproxy/dhparams.pem"
  73. # firstmatch: yes
  74. # state: present
  75. #
  76. #- name: Copy HAProxy configuration in place
  77. # set_fact:
  78. # cfg_content: "{{ lookup('template', '{{ role_path }}/templates/haproxy.cfg.j2') }}"
  79. #
  80. #- name: Merge HAProxy config file
  81. # blockinfile:
  82. # dest: "/etc/haproxy/haproxy.cfg"
  83. # content: '{{ cfg_content }}'
  84. # state: present
  85. - name: Ensure HAProxy conf is set
  86. template:
  87. src: "haproxy_{{ hatarget }}.cfg.j2"
  88. dest: /etc/haproxy/haproxy.cfg
  89. mode: 0640
  90. #- name: HAProxy start
  91. # service: name=haproxy state=started
  92. - name: HAProxy reload
  93. service: name=haproxy state=restarted