Define service and configure consul-template
This commit is contained in:
parent
2107339712
commit
60768a2808
8 changed files with 83 additions and 16 deletions
|
@ -1,4 +1,4 @@
|
|||
{% from "consul/map.jinja" import consul with context %}
|
||||
{% from "consul/map.jinja" import consul, consul_template with context %}
|
||||
|
||||
consul-config:
|
||||
file.managed:
|
||||
|
@ -38,3 +38,9 @@ consul-script-config:
|
|||
- group: consul
|
||||
- require:
|
||||
- user: consul
|
||||
|
||||
consul-template-config:
|
||||
file.managed:
|
||||
- source: salt://consul/files/consul-template-config.json
|
||||
- template: jinja
|
||||
- name: /etc/consul-template.d/config.json
|
||||
|
|
|
@ -5,9 +5,6 @@ consul:
|
|||
ui_version: 0.6.1
|
||||
ui_hash: afccdd540b166b778c7c0483becc5e282bbbb1ee52335bfe94bf757df8c55efc
|
||||
|
||||
template_version: 0.12.1
|
||||
template_hash: 693c52a2b1aed9b63584f47c377efd0fc349df3616985a0709246faaf9a80c8e
|
||||
|
||||
service: false
|
||||
config:
|
||||
server: false
|
||||
|
@ -22,3 +19,12 @@ consul:
|
|||
datacenter: "main"
|
||||
register: []
|
||||
scripts: []
|
||||
|
||||
consul_template:
|
||||
version: 0.12.1
|
||||
hash: 693c52a2b1aed9b63584f47c377efd0fc349df3616985a0709246faaf9a80c8e
|
||||
|
||||
service: false
|
||||
config:
|
||||
consul: 127.0.0.1:8500
|
||||
log_level: info
|
||||
|
|
2
consul/files/consul-template-config.json
Normal file
2
consul/files/consul-template-config.json
Normal file
|
@ -0,0 +1,2 @@
|
|||
{% from "consul/map.jinja" import consul_template with context %}
|
||||
{{ consul_template.config | json}}
|
13
consul/files/consul-template.service
Normal file
13
consul/files/consul-template.service
Normal 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
|
14
consul/files/consul.service
Normal file
14
consul/files/consul.service
Normal 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
|
|
@ -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:
|
||||
pkg.installed:
|
||||
|
@ -42,6 +42,15 @@ consul-data-dir:
|
|||
- group: consul
|
||||
- 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
|
||||
consul-download:
|
||||
file.managed:
|
||||
|
@ -117,20 +126,20 @@ consul-ui-link:
|
|||
# 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 }}
|
||||
- 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
|
||||
- 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 }}
|
||||
- name: /usr/local/bin/consul-template-{{ consul_template.version }}
|
||||
- source: /tmp/consul-template
|
||||
- require:
|
||||
- file: /usr/local/bin
|
||||
|
@ -139,13 +148,13 @@ consul-template-install:
|
|||
|
||||
consul-template-clean:
|
||||
file.absent:
|
||||
- name: /tmp/consul_template_{{ consul.template_version }}_linux_amd64.zip
|
||||
- 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 }}
|
||||
- target: consul-template-{{ consul_template.version }}
|
||||
- name: /usr/local/bin/consul-template
|
||||
- watch:
|
||||
- file: consul-template-install
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% import_yaml "consul/defaults.yaml" as defaults %}
|
||||
|
||||
{% 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 []}) %}
|
||||
|
|
|
@ -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:
|
||||
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
|
||||
- name: /etc/init/consul.conf
|
||||
- mode: 0644
|
||||
|
@ -16,6 +20,18 @@ consul-init-script:
|
|||
- service: consul
|
||||
{% 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 %}
|
||||
consul-service:
|
||||
service.running:
|
||||
|
|
Loading…
Reference in a new issue