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:
parent
60768a2808
commit
347937ad46
16 changed files with 122 additions and 80 deletions
22
consul-template/config.sls
Normal file
22
consul-template/config.sls
Normal 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 %}
|
15
consul-template/defaults.yaml
Normal file
15
consul-template/defaults.yaml
Normal 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
|
2
consul-template/files/config.json
Normal file
2
consul-template/files/config.json
Normal file
|
@ -0,0 +1,2 @@
|
|||
{% from "consul-template/map.jinja" import consul_template with context %}
|
||||
{{ consul_template.config | json }}
|
|
@ -10,4 +10,4 @@ ExecReload=/bin/kill -HUP $MAINPID
|
|||
KillSignal=TERM
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
WantedBy=multi-user.target
|
1
consul-template/files/example.tmpl
Normal file
1
consul-template/files/example.tmpl
Normal file
|
@ -0,0 +1 @@
|
|||
{{with node}}{{.Node.Node}}{{end}}
|
7
consul-template/init.sls
Normal file
7
consul-template/init.sls
Normal 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
|
46
consul-template/install.sls
Normal file
46
consul-template/install.sls
Normal 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
|
3
consul-template/map.jinja
Normal file
3
consul-template/map.jinja
Normal 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) %}
|
21
consul-template/service.sls
Normal file
21
consul-template/service.sls
Normal 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 %}
|
|
@ -1,4 +1,4 @@
|
|||
{% from "consul/map.jinja" import consul, consul_template with context %}
|
||||
{% from "consul/map.jinja" import consul with context %}
|
||||
|
||||
consul-config:
|
||||
file.managed:
|
||||
|
@ -38,9 +38,3 @@ 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
|
||||
|
|
|
@ -19,12 +19,3 @@ 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
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
{% from "consul/map.jinja" import consul_template with context %}
|
||||
{{ consul_template.config | json}}
|
|
@ -11,4 +11,4 @@ KillSignal=TERM
|
|||
User=consul
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
WantedBy=multi-user.target
|
||||
|
|
|
@ -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:
|
||||
pkg.installed:
|
||||
|
@ -42,15 +42,6 @@ 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:
|
||||
|
@ -122,39 +113,3 @@ consul-ui-link:
|
|||
- name: /usr/local/share/consul/ui
|
||||
- watch:
|
||||
- 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
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{% 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,4 +1,4 @@
|
|||
{% from "consul/map.jinja" import consul, consul_template with context %}
|
||||
{% from "consul/map.jinja" import consul with context %}
|
||||
|
||||
consul-init-script:
|
||||
file.managed:
|
||||
|
@ -20,18 +20,6 @@ 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