diff --git a/roles/consul/defaults/main.yml b/roles/consul/defaults/main.yml index fe307e8..9cd6d69 100644 --- a/roles/consul/defaults/main.yml +++ b/roles/consul/defaults/main.yml @@ -70,6 +70,8 @@ consul_base_conf: enabled: "{{ (inventory_hostname in consul_servers) | ternary(True, False) }}" connect: enabled: "{{ (inventory_hostname in consul_servers) | ternary(True, False) }}" + performance: + raft_multiplier: 1 # For example # consul_extra_conf: diff --git a/roles/consul/tasks/conf.yml b/roles/consul/tasks/conf.yml index 5ff56cb..fd6fc25 100644 --- a/roles/consul/tasks/conf.yml +++ b/roles/consul/tasks/conf.yml @@ -1,6 +1,12 @@ --- - name: Deploy consul configuration - template: src=consul.json.j2 dest={{ consul_root_dir }}/etc/consul.json owner=root group={{ consul_user }} mode=640 - notify: reload consul + template: + src: consul.json.j2 + dest: "{{ consul_root_dir }}/etc/consul.json" + owner: root + group: "{{ consul_user }}" + mode: 640 + validate: consul validate %s + notify: restart consul tags: consul diff --git a/roles/consul/tasks/install.yml b/roles/consul/tasks/install.yml index 664edc9..7df808f 100644 --- a/roles/consul/tasks/install.yml +++ b/roles/consul/tasks/install.yml @@ -53,3 +53,9 @@ when: consul_unit.changed tags: consul +- name: Install backup hooks + template: src={{ item }}-backup.j2 dest=/etc/backup/{{ item }}.d/consul mode=755 + loop: + - pre + - post + tags: consul diff --git a/roles/consul/templates/post-backup.j2 b/roles/consul/templates/post-backup.j2 new file mode 100644 index 0000000..ceeb438 --- /dev/null +++ b/roles/consul/templates/post-backup.j2 @@ -0,0 +1,4 @@ +#!/bin/sh + +set -eo pipefail +rm -f {{ consul_root_dir }}/backup/consul.snap diff --git a/roles/consul/templates/pre-backup.j2 b/roles/consul/templates/pre-backup.j2 new file mode 100644 index 0000000..7626f57 --- /dev/null +++ b/roles/consul/templates/pre-backup.j2 @@ -0,0 +1,4 @@ +#!/bin/sh + +set -eo pipefail +consul snapshot save {{ consul_root_dir }}/backup/consul.snap diff --git a/roles/nomad/defaults/main.yml b/roles/nomad/defaults/main.yml index c5a39c8..959cfab 100644 --- a/roles/nomad/defaults/main.yml +++ b/roles/nomad/defaults/main.yml @@ -18,19 +18,21 @@ nomad_user: "{{ nomad_conf.client.enabled | ternary('root', 'nomad') }}" nomad_servers: [] # Ports used by Nomad, the protocols, and the list of IP/CIDR for which the ports will be opened in the firewall -nomad_services: +nomad_base_services: http_api: - port: 4646 + port: "{{ nomad_conf.ports.http | default(4646) }}" proto: [tcp] src_ip: [] rpc: - port: 4647 + port: "{{ nomad_conf.ports.rpc | default(4647) }}" proto: [tcp] src_ip: [] serf: - port: 4648 + port: "{{ nomad_conf.ports.serf | default(4648) }}" proto: [tcp,udp] src_ip: [] +nomad_extra_services: {} +nomad_services: "{{ nomad_base_services | combine(nomad_extra_services, recursive=True) }}" # Nomad configuration (which will be converted to JSON) # The configuration is splited in a base conf, an extra conf, and a host conf so you can override part of the config easily @@ -47,10 +49,6 @@ nomad_base_conf: server_join: retry_join: "{{ (inventory_hostname in nomad_servers) | ternary(nomad_servers, []) }}" bootstrap_expect: "{{ nomad_servers | length }}" - ports: - http: "{{ nomad_services.http_api.port }}" - rpc: "{{ nomad_services.rpc.port }}" - serf: "{{ nomad_services.serf.port }}" # For example # nomad_extra_conf: diff --git a/roles/nomad/tasks/conf.yml b/roles/nomad/tasks/conf.yml index 6dba2a5..a3146af 100644 --- a/roles/nomad/tasks/conf.yml +++ b/roles/nomad/tasks/conf.yml @@ -1,6 +1,12 @@ --- - name: Deploy nomad configuration - template: src=nomad.json.j2 dest={{ nomad_root_dir }}/etc/nomad.json owner=root group={{ nomad_user }} mode=640 + template: + src: nomad.json.j2 + dest: "{{ nomad_root_dir }}/etc/nomad.json" + owner: root + group: "{{ nomad_user }}" + mode: 640 + validate: nomad config validate %s notify: restart nomad tags: nomad