From 8179fd8b6ba5f89329b674d0f877e56350dbc732 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Mon, 1 Aug 2022 19:00:22 +0200 Subject: [PATCH] Update to 2022-08-01 19:00 --- roles/consul/defaults/main.yml | 12 +++++++++++ roles/consul/tasks/conf.yml | 2 +- roles/consul/templates/consul.hcl.j2 | 30 +++++++++++++++++++++------- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/roles/consul/defaults/main.yml b/roles/consul/defaults/main.yml index 61a4ee3..1523974 100644 --- a/roles/consul/defaults/main.yml +++ b/roles/consul/defaults/main.yml @@ -23,6 +23,9 @@ consul_base_conf: log_level: INFO bind_addr: 0.0.0.0 + # Recursive DNS resolver to which non authoritative queries will be sent + recursors: "{{ ansible_dns.nameservers }}" + # Address that is advertised to the other nodes advertise_addr: "{{ ansible_default_ipv4.address }}" # You can also advertise the WAN addr @@ -34,6 +37,12 @@ consul_base_conf: # Node name, which should be uniq in the region. Default is the hostname # node_name: nomade-fr-zone-c + # Arbitrary metadata + # node_meta: + # instance_type: t2.medium + # env: staging + node_meta: {} + # Optional encryption key for the gossip protocol # You can generate one with cinsul keygen. The key should be the same on all the members # encrypt: WSnGbK30nI6K/xk9w+AAtk0Y3RMXKoAlsj4VEICqi0I= @@ -49,6 +58,9 @@ consul_base_conf: performance: raft_multiplier: 1 + telemetry: + prometheus_retention_time: 1h + consul_extra_conf: {} consul_host_conf: {} consul_conf: "{{ consul_base_conf | combine(consul_extra_conf, recursive=True) | combine(consul_host_conf, recursive=True) }}" diff --git a/roles/consul/tasks/conf.yml b/roles/consul/tasks/conf.yml index 38cde13..2fdd57f 100644 --- a/roles/consul/tasks/conf.yml +++ b/roles/consul/tasks/conf.yml @@ -7,6 +7,6 @@ owner: root group: "{{ consul_user }}" mode: 0640 - #validate: consul validate %s + validate: consul validate -config-format=hcl %s notify: restart consul tags: consul diff --git a/roles/consul/templates/consul.hcl.j2 b/roles/consul/templates/consul.hcl.j2 index e63201d..29a9102 100644 --- a/roles/consul/templates/consul.hcl.j2 +++ b/roles/consul/templates/consul.hcl.j2 @@ -13,6 +13,12 @@ datacenter = "{{ consul_conf.datacenter }}" node_name = {{ consul_conf.node_name }} {% endif %} +node_meta { +{% for meta in consul_conf.node_meta.keys() | list %} + {{ meta }} = "{{ consul_conf.node_meta[meta] }}" +{% endfor %} +} + ports { {% for service in consul_services.keys() | list %} {% if service not in ['sidecar', 'expose'] and consul_services[service].port is defined %} @@ -24,19 +30,19 @@ ports { {% endfor %} } -bootstrap_expect = {{ consul_conf.bootstrap_expect }} - -performance { - raft_multiplier = {{ consul_conf.performance.raft_multiplier }} -} - retry_join = [ {% for server in consul_servers %} "{{ server }}", {% endfor %} ] -server = {{ consul_conf.server | ternary('true', 'false') }} +{% if consul_conf.server %} +server = true +bootstrap_expect = {{ consul_conf.bootstrap_expect }} +performance { + raft_multiplier = {{ consul_conf.performance.raft_multiplier }} +} +{% endif %} {% if consul_conf.encrypt is defined %} encrypt = "{{ consul_conf.encrypt }}" @@ -45,3 +51,13 @@ encrypt = "{{ consul_conf.encrypt }}" ui_config { enabled = {{ consul_conf.ui_config.enabled | ternary('true', 'false') }} } + +recursors = [ +{% for dns in consul_conf.recursors %} + "{{ dns }}", +{% endfor %} +] + +telemetry { + prometheus_retention_time = "{{ consul_conf.telemetry.prometheus_retention_time }}" +}