12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- ---
- - name: Get HAProxy version.
- command: haproxy -v
- register: haproxy_version_result
- changed_when: false
- check_mode: false
- - name: Set HAProxy version.
- set_fact:
- haproxy_version: '{{ haproxy_version_result.stdout_lines[0] | regex_replace("^HA-Proxy version ([0-9]\.[0-9]).*$", "\1") }}'
- - name: Ensure HAProxy is started and enabled on boot.
- service: name=haproxy state=started enabled=yes
- - name: Create private key (RSA, 4096 bits)
- community.crypto.openssl_privatekey:
- path: "{{ ssl_crt_path }}/{{ ssl_name }}.key"
- when: ssl_self
- - name: Create certificate signing request (CSR) for self-signed certificate
- community.crypto.openssl_csr_pipe:
- privatekey_path: "{{ ssl_crt_path }}/{{ ssl_name }}.key"
- country_name: BE
- locality_name: Louvain-la-Neuve
- common_name: "{{ ssl_name }}"
- organization_name: UCLouvain
- organizational_unit_name: ELIC
- register: csr
- when: ssl_self
- - name: Generate a Self Signed OpenSSL certificate
- community.crypto.x509_certificate:
- path: "{{ ssl_crt_path }}/{{ ssl_name }}.crt"
- csr_content: "{{ csr.csr }}"
- privatekey_path: "{{ ssl_crt_path }}/{{ ssl_name }}.key"
- provider: selfsigned
- when: ssl_self
- - name: Merge KEY and CRT to generate PEM
- shell: "cat {{ ssl_crt_path }}/{{ ssl_name }}.key {{ ssl_crt_path }}/{{ ssl_name }}.crt >> {{ ssl_crt_path }}/{{ ssl_name }}.pem"
- when: ssl_self
- - name: Generate DH Parameters with a different size (2048 bits)
- community.crypto.openssl_dhparam:
- path: /etc/haproxy/dhparams.pem
- size: 2048
- - name: Add ssl dhparam file
- lineinfile:
- path: /etc/haproxy/haproxy.cfg
- insertafter: "^.*ssl-default-bind-options.*"
- line: "\tssl-dh-param-file /etc/haproxy/dhparams.pem"
- firstmatch: yes
- state: present
- - name: Copy HAProxy configuration in place
- set_fact:
- cfg_content: "{{ lookup('template', '{{ role_path }}/templates/haproxy.cfg.j2') }}"
- - name: Merge HAProxy config file
- blockinfile:
- dest: "/etc/haproxy/haproxy.cfg"
- content: '{{ cfg_content }}'
- state: present
- - name: HAProxy restart
- service: name=haproxy state=restarted
|