start working on supporting different versions of consul-template

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2015-02-24 23:59:06 +01:00
parent 2677130e0c
commit 3c720640dd
9 changed files with 65 additions and 16 deletions

View file

@ -0,0 +1 @@
1356006333 8496656 consul-template

View file

@ -0,0 +1 @@
https://github.com/hashicorp/consul-template/releases/download/v0.6.5/consul-template_0.6.5_linux_amd64.tar.gz

View file

@ -10,8 +10,11 @@ cdist-type__consul_template - manage the consul-template service
DESCRIPTION
-----------
Installs consul-template, generates a global config file and creates directory
for per template config files.
Downloads and installs the consul-template binary from
https://github.com/hashicorp/consul-template/releases/download/.
Generates a global config file and creates directory for per template config files.
Note that the consul-template binary is downloaded on the server (the machine running
cdist) and then deployed to the target host using the __file type.
REQUIRED PARAMETERS
@ -28,14 +31,21 @@ batch-size::
consul::
the location of the Consul instance to query (may be an IP address or FQDN) with port.
Defaults to 'localhost:8500'.
install-to::
where to install the binary. Defaults to /usr/local/bin/consul-template
max-stale::
the maximum staleness of a query. If specified, Consul will distribute work among all
servers instead of just the leader.
retry::
the amount of time to wait if Consul returns an error when communicating
with the API.
state::
either 'present' or 'absent'. Defaults to 'present'
token::
the Consul API token.
version::
which version of consul-template to install. See ./files/versions for a list of
supported versions. Defaults to the latest known version.
wait::
the minimum(:maximum) to wait before rendering a new template to disk and
triggering a command, separated by a colon (:). If the optional maximum
@ -57,6 +67,11 @@ EXAMPLES
__consul_template \
--consul consul.service.consul:8500 \
--retry 30s
# specific version
__consul_template \
--version 0.6.5 \
--retry 30s
--------------------------------------------------------------------------------

View file

@ -24,7 +24,10 @@ os=$(cat "$__global/explorer/os")
case "$os" in
centos|redhat)
# whitelist safeguard
:
service_onchange='service consul-template status >/dev/null && service consul-template reload || true' \
;;
archlinux)
service_onchange="systemctl status consul-template >/dev/null && systemctl reload consul-template || true"
;;
*)
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
@ -33,7 +36,30 @@ case "$os" in
;;
esac
state="present"
versions_dir="$__type/files/versions"
version="$(cat "$__object/parameter/version")"
version_dir="$versions_dir/$version"
if [ ! -d "$version_dir" ]; then
echo "Unknown consul-template version '$version'. Expected one of:" >&2
ls "$versions_dir" >&2
exit 1
fi
state="$(cat "$__object/parameter/state")"
install_to="$(cat "$__object/parameter/install-to")"
__staged_file "$install_to" \
--source "$(cat "$version_dir/source")" \
--cksum "$(cat "$version_dir/cksum")" \
--fetch-command 'curl -s -L "%s"' \
--prepare-command 'tar -xzf "%s"; cat consul-template_*/consul-template' \
--state "$state" \
--group root \
--owner root \
--mode 755
conf_dir="/etc/consul-template/conf.d"
conf_file="config.hcl"
template_dir="/etc/consul-template/template"
@ -48,17 +74,6 @@ require="__directory/etc/consul-template" \
--owner root --group root --mode 750
__staged_file /usr/local/bin/consul-template \
--source https://github.com/hashicorp/consul-template/releases/download/v0.6.5/consul-template_0.6.5_linux_amd64.tar.gz \
--cksum '1356006333 8496656 consul-template' \
--fetch-command 'curl -s -L "%s"' \
--prepare-command 'tar -xzf "%s"; cat consul-template_*/consul-template' \
--state present \
--group root \
--owner root \
--mode 755
# Generate hcl config file
(
for param in $(ls "$__object/parameter/"); do
@ -82,7 +97,7 @@ require="__directory${conf_dir}" \
__config_file "${conf_dir}/${conf_file}" \
--owner root --group root --mode 640 \
--state "$state" \
--onchange 'service consul-template status >/dev/null && service consul-template reload || true' \
--onchange "$service_onchange" \
--source -
@ -118,4 +133,12 @@ case "$os" in
export require="__file/etc/init/${service}.conf"
__start_on_boot "$service" --state "$state"
;;
archlinux)
__file "/lib/systemd/system/${service}.service" \
--owner root --group root --mode 0555 \
--state "$state" \
--source "$__type/files/${service}.systemd"
export require="__file/lib/systemd/system/${service}.service"
__start_on_boot "$service" --state "$state"
;;
esac

View file

@ -0,0 +1 @@
/usr/local/bin/consul-template

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1 @@
0.6.5

View file

@ -1,7 +1,10 @@
auth
batch-size
consul
install-to
max-stale
retry
state
token
version
wait

View file

@ -0,0 +1,3 @@
- add support for --install-to in init-system files/templates
- add support for latest version 0.7.0
- config file format has changed