Separate consul and consul-template states

Break up the consul formula into two states: consul and consul-template
such that it is possible to install consul without consul-template.

Update consul and consul-template to 0.6.4 and 0.14.0 respectively.

Consul template can now be configured with pillars.
This commit is contained in:
George Robinson 2016-04-22 13:35:04 +01:00
parent 60768a2808
commit 347937ad46
16 changed files with 122 additions and 80 deletions

View file

@ -0,0 +1,22 @@
{% from "consul-template/map.jinja" import consul_template with context %}
consul-template-config:
file.managed:
- source: salt://consul-template/files/config.json
- template: jinja
- name: /etc/consul-template.d/config.json
{% if consul_template.tmpl %}
{% for tmpl in consul_template.tmpl %}
consul-template-tmpl-file-{{ loop.index }}:
file.managed:
- source: {{ tmpl.source }}
- name: /etc/consul-template/tmpl-source/{{ tmpl.name }}.ctmpl
consul-template.d-tmpl-{{ loop.index }}:
file.serialize:
- name: /etc/consul-template.d/{{ tmpl.name }}.json
- dataset: {{ tmpl.config }}
- formatter: json
{% endfor %}
{% endif %}

View file

@ -0,0 +1,15 @@
consul_template:
version: 0.14.0
hash: 7c70ea5f230a70c809333e75fdcff2f6f1e838f29cfb872e1420a63cdf7f3a78
service: false
config:
consul: 127.0.0.1:8500
log_level: info
tmpl:
- name: example
source: salt://consul-template/files/example.tmpl
config:
template:
source: /etc/consul-template/tmpl-source/example.ctmpl
destination: /etc/consul-template/example

View file

@ -0,0 +1,2 @@
{% from "consul-template/map.jinja" import consul_template with context %}
{{ consul_template.config | json }}

View file

@ -10,4 +10,4 @@ ExecReload=/bin/kill -HUP $MAINPID
KillSignal=TERM KillSignal=TERM
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -0,0 +1 @@
{{with node}}{{.Node.Node}}{{end}}

7
consul-template/init.sls Normal file
View file

@ -0,0 +1,7 @@
{% from "consul-template/map.jinja" import consul with context %}
include:
- consul
- consul-template.install
- consul-template.config
- consul-template.service

View file

@ -0,0 +1,46 @@
{% from "consul-template/map.jinja" import consul_template with context %}
consul-template-config-dir:
file.directory:
- name: /etc/consul-template.d
consul-template-template-dir:
file.directory:
- name: /etc/consul-template/tmpl-source
- makedirs: True
# Install template renderer
consul-template-download:
file.managed:
- name: /tmp/consul_template_{{ consul_template.version }}_linux_amd64.zip
- source: https://releases.hashicorp.com/consul-template/{{ consul_template.version }}/consul-template_{{ consul_template.version }}_linux_amd64.zip
- source_hash: sha256={{ consul_template.hash }}
- unless: test -f /usr/local/bin/consul-template-{{ consul_template.version }}
consul-template-extract:
cmd.wait:
- name: unzip /tmp/consul_template_{{ consul_template.version }}_linux_amd64.zip -d /tmp
- watch:
- file: consul-template-download
consul-template-install:
file.rename:
- name: /usr/local/bin/consul-template-{{ consul_template.version }}
- source: /tmp/consul-template
- require:
- file: /usr/local/bin
- watch:
- cmd: consul-template-extract
consul-template-clean:
file.absent:
- name: /tmp/consul_template_{{ consul_template.version }}_linux_amd64.zip
- watch:
- file: consul-template-install
consul-template-link:
file.symlink:
- target: consul-template-{{ consul_template.version }}
- name: /usr/local/bin/consul-template
- watch:
- file: consul-template-install

View file

@ -0,0 +1,3 @@
{% import_yaml "consul-template/defaults.yaml" as defaults %}
{% set consul_template = salt['pillar.get']('consul_template', default=defaults.consul_template, merge=True) %}

View file

@ -0,0 +1,21 @@
{% from "consul-template/map.jinja" import consul_template with context %}
consul-template-init-script:
file.managed:
{% if salt['test.provider']('service') == 'systemd' %}
- source: salt://consul-template/files/consul-template.service
- name: /etc/systemd/system/consul-template.service
- mode: 0644
{% endif %}
{% if consul_template.service != False %}
- watch_in:
- service: consul
{% endif %}
{% if consul_template.service != False %}
consul-template-service:
service.running:
- name: consul-template
- watch:
- file: /etc/consul-template.d/*
{% endif %}

View file

@ -1,4 +1,4 @@
{% from "consul/map.jinja" import consul, consul_template with context %} {% from "consul/map.jinja" import consul with context %}
consul-config: consul-config:
file.managed: file.managed:
@ -38,9 +38,3 @@ consul-script-config:
- group: consul - group: consul
- require: - require:
- user: consul - user: consul
consul-template-config:
file.managed:
- source: salt://consul/files/consul-template-config.json
- template: jinja
- name: /etc/consul-template.d/config.json

View file

@ -19,12 +19,3 @@ consul:
datacenter: "main" datacenter: "main"
register: [] register: []
scripts: [] scripts: []
consul_template:
version: 0.12.1
hash: 693c52a2b1aed9b63584f47c377efd0fc349df3616985a0709246faaf9a80c8e
service: false
config:
consul: 127.0.0.1:8500
log_level: info

View file

@ -1,2 +0,0 @@
{% from "consul/map.jinja" import consul_template with context %}
{{ consul_template.config | json}}

View file

@ -11,4 +11,4 @@ KillSignal=TERM
User=consul User=consul
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -1,4 +1,4 @@
{% from "consul/map.jinja" import consul, consul_template with context %} {% from "consul/map.jinja" import consul with context %}
consul-dep-unzip: consul-dep-unzip:
pkg.installed: pkg.installed:
@ -42,15 +42,6 @@ consul-data-dir:
- group: consul - group: consul
- makedirs: - makedirs:
consul-template-config-dir:
file.directory:
- name: /etc/consul-template.d
consul-template-template-dir:
file.directory:
- name: /etc/consul-template/tmpl-source
- makedirs: True
# Install agent # Install agent
consul-download: consul-download:
file.managed: file.managed:
@ -122,39 +113,3 @@ consul-ui-link:
- name: /usr/local/share/consul/ui - name: /usr/local/share/consul/ui
- watch: - watch:
- file: consul-ui-install - file: consul-ui-install
# Install template renderer
consul-template-download:
file.managed:
- name: /tmp/consul_template_{{ consul_template.version }}_linux_amd64.zip
- source: https://releases.hashicorp.com/consul-template/{{ consul_template.version }}/consul-template_{{ consul_template.version }}_linux_amd64.zip
- source_hash: sha256={{ consul_template.hash }}
- unless: test -f /usr/local/bin/consul-template-{{ consul_template.version }}
consul-template-extract:
cmd.wait:
- name: unzip /tmp/consul_template_{{ consul_template.version }}_linux_amd64.zip -d /tmp
- watch:
- file: consul-template-download
consul-template-install:
file.rename:
- name: /usr/local/bin/consul-template-{{ consul_template.version }}
- source: /tmp/consul-template
- require:
- file: /usr/local/bin
- watch:
- cmd: consul-template-extract
consul-template-clean:
file.absent:
- name: /tmp/consul_template_{{ consul_template.version }}_linux_amd64.zip
- watch:
- file: consul-template-install
consul-template-link:
file.symlink:
- target: consul-template-{{ consul_template.version }}
- name: /usr/local/bin/consul-template
- watch:
- file: consul-template-install

View file

@ -1,6 +1,5 @@
{% import_yaml "consul/defaults.yaml" as defaults %} {% import_yaml "consul/defaults.yaml" as defaults %}
{% set consul = salt['pillar.get']('consul', default=defaults.consul, merge=True) %} {% set consul = salt['pillar.get']('consul', default=defaults.consul, merge=True) %}
{% set consul_template = salt['pillar.get']('consul_template', default=defaults.consul_template, merge=True) %}
{% do consul.config.update({'retry_join': consul.config.retry_join or []}) %} {% do consul.config.update({'retry_join': consul.config.retry_join or []}) %}

View file

@ -1,4 +1,4 @@
{% from "consul/map.jinja" import consul, consul_template with context %} {% from "consul/map.jinja" import consul with context %}
consul-init-script: consul-init-script:
file.managed: file.managed:
@ -20,18 +20,6 @@ consul-init-script:
- service: consul - service: consul
{% endif %} {% endif %}
consul-template-init-script:
file.managed:
{% if salt['test.provider']('service') == 'systemd' %}
- source: salt://consul/files/consul-template.service
- name: /etc/systemd/system/consul-template.service
- mode: 0644
{% endif %}
{% if consul_template.service != False %}
- watch_in:
- service: consul
{% endif %}
{% if consul.service != False %} {% if consul.service != False %}
consul-service: consul-service:
service.running: service.running: