diff --git a/defaults/main.yml b/defaults/main.yml index 2f6bd0f27ee18eafd61f28aff4d07776525b07bb..85602bc8e6f3d7f25ccbddbb32e4c1b7b6685fd7 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -14,10 +14,10 @@ _haproxy_ssl_options: 'no-sslv3 no-tlsv10 no-tlsv11 no-tls-tickets' _haproxy_ssl_ciphers: 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384' _haproxy_ssl_ciphersuites: 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256' -_haproxy_default_compression_algo: gzip -_haproxy_default_compression_type: "text/css text/xml application/javascript application/atom+xml application/rss+xml text/mathml text/plain text/x-component image/svg+xml application/json application/vnd.google-earth.kml+xml application/x-perl application/xhtml+xml application/xspf+xml" +haproxy_default_compression_algo: gzip +haproxy_default_compression_type: "text/css text/xml application/javascript application/atom+xml application/rss+xml text/mathml text/plain text/x-component image/svg+xml application/json application/vnd.google-earth.kml+xml application/x-perl application/xhtml+xml application/xspf+xml" -haproxy_global: +_haproxy_global: log: - address: /dev/log facility: local0 @@ -36,7 +36,7 @@ haproxy_global: tune: ssl.default-dh-param: 2048 -haproxy_defaults: +_haproxy_defaults: mode: http log: - address: /dev/log diff --git a/tasks/configure.yml b/tasks/configure.yml index 9bf33d5b93b01f935ba7ff4fb6dfd166befb9f99..0bcb9407646149bf4186c4776857659ead852a58 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -148,12 +148,18 @@ - name: 'Create the compiled folder' file: path={{ haproxy_config_dir }}/compiled state=directory +- name: 'Merge global config' + set_fact: + haproxy_global_final: "{{ _haproxy_global | combine(haproxy_global, recursive=true)}}" + - name: 'Build up the global config' template: src: "global.cfg" dest: "{{ haproxy_config_dir }}/compiled/01-global.cfg" - when: haproxy_global is defined - tags: 'test' + +- name: 'Merge default config' + set_fact: + haproxy_defaults_final: "{{ _haproxy_defaults | combine(haproxy_defaults, recursive=true)}}" - name: 'Build up the default config' template: diff --git a/templates/_macros.j2 b/templates/_macros.j2 index 2d1296213ef5f2cb00220dea8f9e82d0761861bf..5e2a78aedfa79051eaca404af98871944394f94a 100644 --- a/templates/_macros.j2 +++ b/templates/_macros.j2 @@ -16,13 +16,13 @@ {% if item.algo is defined -%} compression algo {{ item.algo }} {% else -%} - compression algo {{ _haproxy_default_compression_algo }} + compression algo {{ haproxy_default_compression_algo }} {% endif -%} {% if item.type is defined -%} compression type {{ item.type }} {% else -%} - compression type {{ _haproxy_default_compression_type }} + compression type {{ haproxy_default_compression_type }} {% endif -%} {% if item.offload is defined and item.offload == true -%} diff --git a/templates/defaults.cfg b/templates/defaults.cfg index 440a8c81b879b288ad3729afa23c502942a845c2..e01eea6f252179d9b90af3c031055d1b391adbc9 100644 --- a/templates/defaults.cfg +++ b/templates/defaults.cfg @@ -1,10 +1,10 @@ #{{ ansible_managed }} defaults -{% if haproxy_defaults.mode is defined %} - mode {{ haproxy_defaults.mode }} +{% if haproxy_defaults_final.mode is defined %} + mode {{ haproxy_defaults_final.mode }} {% endif -%} -{% if haproxy_defaults.log is defined %} -{% for log in haproxy_defaults.log %} +{% if haproxy_defaults_final.log is defined %} +{% for log in haproxy_defaults_final.log %} log {{ log.address }}{% if log.facility is defined %} {{ log.facility }} {% endif %}{% if log.level is defined %} {{log.level }} {% endif %}{% if log.minlevel is defined %} {{ log.minlevel }}{% endif %} {% if log.format is defined %} @@ -13,65 +13,65 @@ defaults {% endfor %} {% endif %} -{% if haproxy_defaults.retries is defined %} - retries {{ haproxy_defaults.retries }} +{% if haproxy_defaults_final.retries is defined %} + retries {{ haproxy_defaults_final.retries }} {% endif -%} -{% if haproxy_defaults.timeout is defined -%} -{% for condition in haproxy_defaults.timeout %} +{% if haproxy_defaults_final.timeout is defined -%} +{% for condition in haproxy_defaults_final.timeout %} timeout {{ condition.param }} {{ condition.value }} {% endfor %} {% endif -%} -{% if haproxy_defaults.maxconn is defined %} - maxconn {{ haproxy_defaults.maxconn }} +{% if haproxy_defaults_final.maxconn is defined %} + maxconn {{ haproxy_defaults_final.maxconn }} {% endif -%} -{% if haproxy_defaults.stats is defined %} -{% if haproxy_defaults.stats.enabled is defined and haproxy_defaults.stats.enabled == True %} +{% if haproxy_defaults_final.stats is defined %} +{% if haproxy_defaults_final.stats.enabled is defined and haproxy_defaults_final.stats.enabled == True %} stats enable {% endif -%} -{% if haproxy_defaults.stats.hide_version is defined and haproxy_defaults.stats.hide_version == true %} +{% if haproxy_defaults_final.stats.hide_version is defined and haproxy_defaults_final.stats.hide_version == true %} stats hide-version {% endif -%} -{% if haproxy_defaults.stats.uri is defined %} - stats uri {{ haproxy_defaults.stats.uri }} +{% if haproxy_defaults_final.stats.uri is defined %} + stats uri {{ haproxy_defaults_final.stats.uri }} {% endif -%} -{% if haproxy_defaults.stats.realm is defined %} - stats realm {{ haproxy_defaults.stats.realm }} +{% if haproxy_defaults_final.stats.realm is defined %} + stats realm {{ haproxy_defaults_final.stats.realm }} {% endif -%} -{% if haproxy_defaults.stats.auth is defined %} - stats auth {{ haproxy_defaults.stats.auth }} +{% if haproxy_defaults_final.stats.auth is defined %} + stats auth {{ haproxy_defaults_final.stats.auth }} {% endif -%} -{% if haproxy_defaults.stats.refresh is defined %} - stats refresh {{ haproxy_defaults.stats.refresh }} +{% if haproxy_defaults_final.stats.refresh is defined %} + stats refresh {{ haproxy_defaults_final.stats.refresh }} {% endif -%} {% endif %} -{% if haproxy_defaults.options is defined %} -{% for option in haproxy_defaults.options %} +{% if haproxy_defaults_final.options is defined %} +{% for option in haproxy_defaults_final.options %} option {{ option }} {% endfor -%} {% endif -%} {% if ansible_distribution != 'CentOS' and ansible_distribution != 'Alpine' %} -{% if haproxy_defaults.errorfile is defined %} -{% for item in haproxy_defaults.errorfile %} +{% if haproxy_defaults_final.errorfile is defined %} +{% for item in haproxy_defaults_final.errorfile %} errorfile {{ item.code }} {{ item.file }} {% endfor %} {% endif -%} {% endif -%} -{% if haproxy_defaults.balance is defined %} - balance {{ haproxy_defaults.balance }} +{% if haproxy_defaults_final.balance is defined %} + balance {{ haproxy_defaults_final.balance }} {% endif -%} -{% if haproxy_defaults.compression is defined -%} - {{ macros.compression(haproxy_defaults.compression) }} +{% if haproxy_defaults_final.compression is defined -%} + {{ macros.compression(haproxy_defaults_final.compression) }} {% endif -%} -{% if haproxy_defaults.http_check is defined %} -{% if haproxy_defaults.http_check.disable_on_404 is defined and haproxy_defaults.http_check.disable_on_404 == true %} +{% if haproxy_defaults_final.http_check is defined %} +{% if haproxy_defaults_final.http_check.disable_on_404 is defined and haproxy_defaults_final.http_check.disable_on_404 == true %} http-check disable-on-404 {% endif -%} -{% if haproxy_defaults.http_check.expect is defined %} - http-check expect {{ haproxy_defaults.http_check.expect }} +{% if haproxy_defaults_final.http_check.expect is defined %} + http-check expect {{ haproxy_defaults_final.http_check.expect }} {% endif -%} -{% if haproxy_defaults.http_check.send_state is defined and haproxy_defaults.http_check.send_state == true %} +{% if haproxy_defaults_final.http_check.send_state is defined and haproxy_defaults_final.http_check.send_state == true %} http-check send-state {% endif -%} {% endif -%} diff --git a/templates/global.cfg b/templates/global.cfg index ecbfa1d18770f7b12c29914af638376033aac3c8..5ec64023b932a16bc4f129f62f6131ab90f50165 100644 --- a/templates/global.cfg +++ b/templates/global.cfg @@ -1,43 +1,43 @@ #{{ ansible_managed }} global -{% if haproxy_global.chroot is defined and haproxy_global.chroot != false %} - chroot {{ haproxy_global.chroot }} +{% if haproxy_global_final.chroot is defined and haproxy_global_final.chroot != false %} + chroot {{ haproxy_global_final.chroot }} {% endif -%} -{% if haproxy_global.pidfile is defined %} - pidfile {{ haproxy_global.pidfile }} +{% if haproxy_global_final.pidfile is defined %} + pidfile {{ haproxy_global_final.pidfile }} {% endif -%} -{% if haproxy_global.maxconn is defined %} - maxconn {{ haproxy_global.maxconn }} +{% if haproxy_global_final.maxconn is defined %} + maxconn {{ haproxy_global_final.maxconn }} {% endif -%} -{% if haproxy_global.uid is defined %} - uid {{ haproxy_global.uid }} -{% elif haproxy_global.user is defined %} - user {{ haproxy_global.user }} +{% if haproxy_global_final.uid is defined %} + uid {{ haproxy_global_final.uid }} +{% elif haproxy_global_final.user is defined %} + user {{ haproxy_global_final.user }} {% endif -%} -{% if haproxy_global.gid is defined %} - gid {{ haproxy_global.gid }} -{% elif haproxy_global.group is defined %} - group {{ haproxy_global.group }} +{% if haproxy_global_final.gid is defined %} + gid {{ haproxy_global_final.gid }} +{% elif haproxy_global_final.group is defined %} + group {{ haproxy_global_final.group }} {% endif -%} -{% if haproxy_global.daemon is defined and haproxy_global.daemon == true %} +{% if haproxy_global_final.daemon is defined and haproxy_global_final.daemon == true %} daemon {% endif -%} -{% if haproxy_global.nbproc is defined %} - nbproc {{ haproxy_global.nbproc }} +{% if haproxy_global_final.nbproc is defined %} + nbproc {{ haproxy_global_final.nbproc }} {% endif -%} -{% if haproxy_global.spread_checks is defined %} - spread-checks {{ haproxy_global.spread_checks }} +{% if haproxy_global_final.spread_checks is defined %} + spread-checks {{ haproxy_global_final.spread_checks }} {% endif -%} -{% if haproxy_global.stats is defined %} -{% if haproxy_global.stats.socket is defined %} - stats socket {{ haproxy_global.stats.socket }} +{% if haproxy_global_final.stats is defined %} +{% if haproxy_global_final.stats.socket is defined %} + stats socket {{ haproxy_global_final.stats.socket }} {% endif -%} -{% if haproxy_global.stats.timeout is defined %} - stats timeout {{ haproxy_global.stats.timeout }} +{% if haproxy_global_final.stats.timeout is defined %} + stats timeout {{ haproxy_global_final.stats.timeout }} {% endif -%} {% endif %} -{% if haproxy_global.log is defined %} -{% for log in haproxy_global.log %} +{% if haproxy_global_final.log is defined %} +{% for log in haproxy_global_final.log %} log {{ log.address }} {{ log.facility }}{% if log.level is defined %} {{log.level }}{% endif %}{% if log.minlevel is defined %} {{ log.minlevel }}{% endif %} {% if log.format is defined %} @@ -45,26 +45,26 @@ global {% endif %} {% endfor %} {% endif %} -{% if haproxy_global.ssl_default_bind_options is defined %} - ssl-default-bind-options {{ haproxy_global.ssl_default_bind_options }} +{% if haproxy_global_final.ssl_default_bind_options is defined %} + ssl-default-bind-options {{ haproxy_global_final.ssl_default_bind_options }} {% endif -%} -{% if haproxy_global.ssl_default_bind_ciphers is defined %} - ssl-default-bind-ciphers {{ haproxy_global.ssl_default_bind_ciphers }} +{% if haproxy_global_final.ssl_default_bind_ciphers is defined %} + ssl-default-bind-ciphers {{ haproxy_global_final.ssl_default_bind_ciphers }} {% endif -%} -{% if haproxy_global.ssl_default_bind_ciphersuites is defined %} - ssl-default-bind-ciphersuites {{ haproxy_global.ssl_default_bind_ciphersuites }} +{% if haproxy_global_final.ssl_default_bind_ciphersuites is defined %} + ssl-default-bind-ciphersuites {{ haproxy_global_final.ssl_default_bind_ciphersuites }} {% endif -%} -{% if haproxy_global.ssl_default_server_options is defined %} - ssl-default-server-options {{ haproxy_global.ssl_default_server_options }} +{% if haproxy_global_final.ssl_default_server_options is defined %} + ssl-default-server-options {{ haproxy_global_final.ssl_default_server_options }} {% endif -%} -{% if haproxy_global.ssl_default_server_ciphers is defined %} - ssl-default-server-ciphers {{ haproxy_global.ssl_default_server_ciphers }} +{% if haproxy_global_final.ssl_default_server_ciphers is defined %} + ssl-default-server-ciphers {{ haproxy_global_final.ssl_default_server_ciphers }} {% endif -%} -{% if haproxy_global.ssl_default_server_ciphersuites is defined %} - ssl-default-server-ciphersuites {{ haproxy_global.ssl_default_server_ciphersuites }} +{% if haproxy_global_final.ssl_default_server_ciphersuites is defined %} + ssl-default-server-ciphersuites {{ haproxy_global_final.ssl_default_server_ciphersuites }} {% endif -%} -{% if haproxy_global.tune is defined %} - {% for param, value in (haproxy_global.tune).items()%} +{% if haproxy_global_final.tune is defined %} + {% for param, value in (haproxy_global_final.tune).items()%} tune.{{ param }} {{ value }} {% endfor %} {% endif %}