From 6bff11039a78944fec329c52ef3c9d52352d8a06 Mon Sep 17 00:00:00 2001 From: Nicolas Ledez Date: Sun, 4 Nov 2018 15:37:07 +0100 Subject: [PATCH 1/2] Use cmd_check to validate config files --- consul/config.sls | 33 +++++++++++++++++++++----------- consul/files/template.json.jinja | 1 + 2 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 consul/files/template.json.jinja diff --git a/consul/config.sls b/consul/config.sls index 44c39c91..87f39c01 100644 --- a/consul/config.sls +++ b/consul/config.sls @@ -1,13 +1,18 @@ {%- from slspath + '/map.jinja' import consul with context -%} consul-config: - file.serialize: + file.managed: - name: /etc/consul.d/config.json - - formatter: json - - dataset: {{ consul.config }} - user: {{ consul.user }} - group: {{ consul.group }} - mode: 0640 + - source: salt://{{ slspath }}/files/template.json.jinja + - template: jinja + - context: + content: + {{ consul.config | yaml }} + - check_cmd: /usr/local/bin/consul validate + - tmp_ext: '.json' - require: - user: consul-user {%- if consul.service %} @@ -28,16 +33,22 @@ consul-script-install-{{ loop.index }}: {% endfor %} consul-script-config: - file.serialize: + file.managed: - name: /etc/consul.d/services.json - {% if consul.service != False %} - - watch_in: - - service: consul - {% endif %} - user: {{ consul.user }} - group: {{ consul.group }} + - mode: 0640 + - source: salt://{{ slspath }}/files/template.json.jinja + - template: jinja + - context: + content: + services: + {{ consul.register | yaml }} + - check_cmd: /usr/local/bin/consul validate /etc/consul.d/config.json + - tmp_ext: '.json' - require: - user: consul-user - - formatter: json - - dataset: - services: {{ consul.register }} + {% if consul.service != False %} + - watch_in: + - service: consul + {% endif %} diff --git a/consul/files/template.json.jinja b/consul/files/template.json.jinja new file mode 100644 index 00000000..9e494f8e --- /dev/null +++ b/consul/files/template.json.jinja @@ -0,0 +1 @@ +{{ content | tojson(indent=2) }} From c9dea92478869b1564fcd1e2791f580d2aa9d136 Mon Sep 17 00:00:00 2001 From: Nicolas Ledez Date: Sun, 4 Nov 2018 17:12:03 +0100 Subject: [PATCH 2/2] Fix consul validate dependencies --- .gitignore | 2 ++ consul/config.sls | 11 +++++++---- pillar.example | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a1bead0f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.kitchen/ +Gemfile.lock diff --git a/consul/config.sls b/consul/config.sls index 87f39c01..036c592b 100644 --- a/consul/config.sls +++ b/consul/config.sls @@ -11,13 +11,14 @@ consul-config: - context: content: {{ consul.config | yaml }} - - check_cmd: /usr/local/bin/consul validate - - tmp_ext: '.json' - require: - user: consul-user {%- if consul.service %} + - file: /usr/local/bin/consul - watch_in: - service: consul + - check_cmd: /usr/local/bin/consul validate + - tmp_ext: '.json' {%- endif %} {% for script in consul.scripts %} @@ -44,11 +45,13 @@ consul-script-config: content: services: {{ consul.register | yaml }} - - check_cmd: /usr/local/bin/consul validate /etc/consul.d/config.json - - tmp_ext: '.json' - require: - user: consul-user {% if consul.service != False %} + - file: /usr/local/bin/consul + - file: /etc/consul.d/config.json - watch_in: - service: consul + - check_cmd: /usr/local/bin/consul validate /etc/consul.d/config.json + - tmp_ext: '.json' {% endif %} diff --git a/pillar.example b/pillar.example index e465f426..2b06f261 100644 --- a/pillar.example +++ b/pillar.example @@ -6,7 +6,7 @@ consul: user: consul group: consul - version: 0.7.0 + version: 1.2.0 download_host: releases.hashicorp.com config: