Define service and configure consul-template

This commit is contained in:
George Robinson 2016-04-22 11:40:14 +01:00
parent 2107339712
commit 60768a2808
8 changed files with 83 additions and 16 deletions

View file

@ -1,4 +1,4 @@
{% from "consul/map.jinja" import consul with context %} {% from "consul/map.jinja" import consul, consul_template with context %}
consul-config: consul-config:
file.managed: file.managed:
@ -38,3 +38,9 @@ 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

@ -5,9 +5,6 @@ consul:
ui_version: 0.6.1 ui_version: 0.6.1
ui_hash: afccdd540b166b778c7c0483becc5e282bbbb1ee52335bfe94bf757df8c55efc ui_hash: afccdd540b166b778c7c0483becc5e282bbbb1ee52335bfe94bf757df8c55efc
template_version: 0.12.1
template_hash: 693c52a2b1aed9b63584f47c377efd0fc349df3616985a0709246faaf9a80c8e
service: false service: false
config: config:
server: false server: false
@ -22,3 +19,12 @@ 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

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

View file

@ -0,0 +1,13 @@
[Unit]
Description=consul-template
Wants=network.target
After=network.target
[Service]
Environment="GOMAXPROCS=2" "PATH=/usr/local/bin:/usr/bin:/bin"
ExecStart=/usr/local/bin/consul-template -config /etc/consul-template.d
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=TERM
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,14 @@
[Unit]
Description=consul
Wants=network.target
After=network.target
[Service]
Environment="GOMAXPROCS=2" "PATH=/usr/local/bin:/usr/bin:/bin"
ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul.d
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=TERM
User=consul
[Install]
WantedBy=multi-user.target

View file

@ -1,4 +1,4 @@
{% from "consul/map.jinja" import consul with context %} {% from "consul/map.jinja" import consul, consul_template with context %}
consul-dep-unzip: consul-dep-unzip:
pkg.installed: pkg.installed:
@ -40,7 +40,16 @@ consul-data-dir:
- name: /usr/local/share/consul - name: /usr/local/share/consul
- user: consul - user: consul
- 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:
@ -117,20 +126,20 @@ consul-ui-link:
# Install template renderer # Install template renderer
consul-template-download: consul-template-download:
file.managed: file.managed:
- name: /tmp/consul_template_{{ consul.template_version }}_linux_amd64.zip - 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: https://releases.hashicorp.com/consul-template/{{ consul_template.version }}/consul-template_{{ consul_template.version }}_linux_amd64.zip
- source_hash: sha256={{ consul.template_hash }} - source_hash: sha256={{ consul_template.hash }}
- unless: test -f /usr/local/bin/consul-template-{{ consul.template_version }} - unless: test -f /usr/local/bin/consul-template-{{ consul_template.version }}
consul-template-extract: consul-template-extract:
cmd.wait: cmd.wait:
- name: unzip /tmp/consul_template_{{ consul.template_version }}_linux_amd64.zip -d /tmp - name: unzip /tmp/consul_template_{{ consul_template.version }}_linux_amd64.zip -d /tmp
- watch: - watch:
- file: consul-template-download - file: consul-template-download
consul-template-install: consul-template-install:
file.rename: file.rename:
- name: /usr/local/bin/consul-template-{{ consul.template_version }} - name: /usr/local/bin/consul-template-{{ consul_template.version }}
- source: /tmp/consul-template - source: /tmp/consul-template
- require: - require:
- file: /usr/local/bin - file: /usr/local/bin
@ -139,13 +148,13 @@ consul-template-install:
consul-template-clean: consul-template-clean:
file.absent: file.absent:
- name: /tmp/consul_template_{{ consul.template_version }}_linux_amd64.zip - name: /tmp/consul_template_{{ consul_template.version }}_linux_amd64.zip
- watch: - watch:
- file: consul-template-install - file: consul-template-install
consul-template-link: consul-template-link:
file.symlink: file.symlink:
- target: consul-template-{{ consul.template_version }} - target: consul-template-{{ consul_template.version }}
- name: /usr/local/bin/consul-template - name: /usr/local/bin/consul-template
- watch: - watch:
- file: consul-template-install - file: consul-template-install

View file

@ -1,5 +1,6 @@
{% 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,8 +1,12 @@
{% from "consul/map.jinja" import consul with context %} {% from "consul/map.jinja" import consul, consul_template with context %}
consul-init-script: consul-init-script:
file.managed: file.managed:
{% if salt['test.provider']('service') == 'upstart' %} {% if salt['test.provider']('service') == 'systemd' %}
- source: salt://consul/files/consul.service
- name: /etc/systemd/system/consul.service
- mode: 0644
{% elif salt['test.provider']('service') == 'upstart' %}
- source: salt://consul/files/consul.upstart - source: salt://consul/files/consul.upstart
- name: /etc/init/consul.conf - name: /etc/init/consul.conf
- mode: 0644 - mode: 0644
@ -16,6 +20,18 @@ 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: