adamkrone / chef-consul-template Goto Github PK
View Code? Open in Web Editor NEWA Chef cookbook that installs and configures consul-template
License: Other
A Chef cookbook that installs and configures consul-template
License: Other
Do you have any plans on publishing this cookbook to the chef supermarket so it's easier to consume?
Upgrading does not appear to be upgrading the binary:
default['consul_template']['version'] = '0.12.0'
default['consul_template']['checksums']['consul-template_0.12.0_linux_amd64'] = '1fff23fa44fd0af0cb56f011a911af1e9d407a2eeb360f520a503d2f330fdf43'
Recipe: consul-template::install_binary
* ark[consul-template] action cherry_pick
* directory[/usr/local/bin] action create (up to date)
* remote_file[/var/chef/cache/consul-template.zip] action create
- create new file /var/chef/cache/consul-template.zip
- update content in file /var/chef/cache/consul-template.zip from none to 1fff23
(new content is binary, diff output suppressed)
* execute[cherry_pick consul-template from /var/chef/cache/consul-template.zip] action nothing (skipped due to action :nothing)
* execute[set owner on /usr/local/bin] action nothing (skipped due to action :nothing)
* execute[cherry_pick consul-template from /var/chef/cache/consul-template.zip] action run (up to date)
* file[/usr/local/bin/consul-template] action touch
- update utime on file /usr/local/bin/consul-template
root@i-014fe1d8# consul-template --version
2015/12/18 02:05:07 [DEBUG] (logging) setting up logging
2015/12/18 02:05:07 [DEBUG] (logging) config:
{
"name": "consul-template",
"level": "WARN",
"syslog": false,
"syslog_facility": "LOCAL0"
}
consul-template v0.10.0
The 0.10.0 release added issues_url
and source_url
lines to metadata.rb. Unfortunately, those are not present in Chef 11 and, as a result, the cookbook cannot be used in Chef 11. This can be fixed while retaining their functionality by adding if respond_to?
guards, like so:
issues_url 'https://github.com/adamkrone/chef-consul-template/issues' if respond_to?(:issues_url)
source_url 'https://github.com/adamkrone/chef-consul-template' if respond_to?(:source_url)
I notice that there are commits in master
which fix a syntax bug I've seen when converging this cookbook on Windows Sever machines, but these commits were made after the current 0.13.0
release:
would it be possible to release this as a 0.13.1
release to Chef Supermarket?
Failing due to libarchive::default recipe
Installing Cookbook Gems:
Compiling Cookbooks...
[2018-05-07T18:58:06+00:00] WARN: The libarchive::default recipe is no longer needed and should not be included on runlists
Converging 10 resources
Recipe: consul-template::install_binary
* remote_file[/tmp/kitchen/cache/consul-template_0.19.4_linux_amd64.zip] action create_if_missing (up to date)
* archive_file[consul-template_0.19.4_linux_amd64.zip] action extract
- create directory /opt/consul-template/consul-template_0.19.4_linux_amd64
Running handlers:
[2018-05-07T18:58:06+00:00] ERROR: Running exception handlers
Running handlers complete
[2018-05-07T18:58:06+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 04 seconds
[2018-05-07T18:58:06+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
[2018-05-07T18:58:06+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2018-05-07T18:58:06+00:00] FATAL: LoadError: Could not open library 'archive': archive: cannot open shared object file: No such file or directory.
Could not open library 'libarchive.so': /lib64/liblzma.so.5: version `XZ_5.2' not found (required by /opt/chef/embedded/lib/libarchive.so).
Could not open library 'libarchive.so.2': libarchive.so.2: cannot open shared object file: No such file or directory
I cannot find the cookbook here any more http://cookbooks.opscode.com/cookbooks?utf8=%E2%9C%93&q=consul. Also:
↳ $ knife cookbook site download consul-template
ERROR: The object you are looking for could not be found
Response:
I got this error:
amazon-ebs: SyntaxError
amazon-ebs: -----------
amazon-ebs: /tmp/packer-chef-solo/cookbooks-1/consul-template/libraries/consul-template_helpers.rb:32: syntax error, unexpected '.'
here's the line of code in question:
path&.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR || '\')
This was running on a linux box I believe.
Thanks for making this open source. I'm using this cookbook to setup consul-template for our nginx load balancing.
It works great, but I have a problem trying to test notification of reload using ChefSpec
Here is my consul_template_config definition
consul_template_config service_name do
templates [{
source: '/etc/nginx/nginx.conf.ctmpl',
destination: '/etc/nginx/nginx.conf',
command: 'service nginx reload'
}]
notifies :reload, 'service[consul-template]', :delayed
end
And here is my ChefSpec test
consul_template = chef_run.consul_template_config(service_name)
expect(consul_template).to notify('service[consul-template]')
.to(:reload).delayed
But I get
Failure/Error: consul_template = chef_run.consul_template_config(service_name)
NoMethodError:
undefined method `consul_template_config' for #<ChefSpec::SoloRunner:0x007fcf5ffbf5f0>
Am I doing something wrong?
Trying to install consul-template into docker debian:jessie.
Version 0.14.0 works fine. But now I need >= 0.18.0, and it doesn't work.
My node json docker-consul-template.json
:
{
"consul_template" : {
"version" : "0.19.0",
"checksums": {
"consul-template_0.19.0_linux_amd64": "31dda6ebc7bd7712598c6ac0337ce8fd8c533229887bd58e825757af879c5f9f"
}
},
"run_list": [
"recipe[consul-template]",
"recipe[rubber::consul-template]"
],
"automatic": {
"ipaddress": "localhost"
}
}
at "recipe[rubber::consul-template]"
right now commented everything
Error:
:install_binary line 20)
[2017-08-21T16:38:02+00:00] INFO: remote_file[/chef/local-mode-cache/cache/consul-template_0.19.0_linux_amd64.zip] created file /chef/local-mode-cache/cache/consul-template_0.19.0_linux_amd64.zip
[2017-08-21T16:38:02+00:00] INFO: remote_file[/chef/local-mode-cache/cache/consul-template_0.19.0_linux_amd64.zip] updated file contents /chef/local-mode-cache/cache/consul-template_0.19.0_linux_amd64.zip
[2017-08-21T16:38:02+00:00] INFO: Processing libarchive_file[consul-template_0.19.0_linux_amd64.zip] action extract (consul-template::install_binary line 26)
[2017-08-21T16:38:02+00:00] INFO: libarchive_file[consul-template_0.19.0_linux_amd64.zip] extracting /chef/local-mode-cache/cache/consul-template_0.19.0_linux_amd64.zip to /usr/local/bin/consul-template_0.19.0_linux_amd64
[2017-08-21T16:38:02+00:00] INFO: Processing link[/usr/local/bin/consul-template] action create (consul-template::install_binary line 34)
[2017-08-21T16:38:02+00:00] INFO: link[/usr/local/bin/consul-template] created
[2017-08-21T16:38:02+00:00] WARN: /usr/local/bin/consul-template mode not changed: File.lchmod is unimplemented on this OS and Ruby version
[2017-08-21T16:38:02+00:00] INFO: link[/usr/local/bin/consul-template] mode changed to 755
[2017-08-21T16:38:02+00:00] INFO: Processing linux_user[root] action create (consul-template::service line 33)
[2017-08-21T16:38:02+00:00] INFO: Processing group[root] action create (consul-template::service line 41)
[2017-08-21T16:38:02+00:00] INFO: Processing directory[/etc/consul-template.d] action create (consul-template::service line 49)
[2017-08-21T16:38:02+00:00] INFO: directory[/etc/consul-template.d] created directory /etc/consul-template.d
[2017-08-21T16:38:02+00:00] INFO: directory[/etc/consul-template.d] owner changed to 0
[2017-08-21T16:38:02+00:00] INFO: directory[/etc/consul-template.d] group changed to 0
[2017-08-21T16:38:02+00:00] INFO: directory[/etc/consul-template.d] mode changed to 755
[2017-08-21T16:38:02+00:00] INFO: Processing file[/etc/consul-template.d/default.json] action create (consul-template::service line 58)
[2017-08-21T16:38:02+00:00] INFO: file[/etc/consul-template.d/default.json] created file /etc/consul-template.d/default.json
[2017-08-21T16:38:02+00:00] INFO: file[/etc/consul-template.d/default.json] updated file contents /etc/consul-template.d/default.json
[2017-08-21T16:38:02+00:00] INFO: file[/etc/consul-template.d/default.json] owner changed to 0
[2017-08-21T16:38:02+00:00] INFO: file[/etc/consul-template.d/default.json] group changed to 0
[2017-08-21T16:38:02+00:00] INFO: file[/etc/consul-template.d/default.json] mode changed to 600
[2017-08-21T16:38:02+00:00] INFO: file[/etc/consul-template.d/default.json] not queuing delayed action restart on service[consul-template] (delayed), as it's already been queued
[2017-08-21T16:38:02+00:00] INFO: Processing template[/etc/init.d/consul-template] action create (consul-template::service line 85)
[2017-08-21T16:38:02+00:00] INFO: template[/etc/init.d/consul-template] created file /etc/init.d/consul-template
[2017-08-21T16:38:02+00:00] INFO: template[/etc/init.d/consul-template] updated file contents /etc/init.d/consul-template
[2017-08-21T16:38:02+00:00] INFO: template[/etc/init.d/consul-template] mode changed to 755
[2017-08-21T16:38:02+00:00] INFO: template[/etc/init.d/consul-template] sending restart action to service[consul-template] (immediate)
[2017-08-21T16:38:02+00:00] INFO: Processing service[consul-template] action restart (consul-template::service line 98)
[2017-08-21T16:38:02+00:00] INFO: service[consul-template] restarted
[2017-08-21T16:38:02+00:00] INFO: Processing service[consul-template] action enable (consul-template::service line 98)
[2017-08-21T16:38:02+00:00] INFO: service[consul-template] enabled
[2017-08-21T16:38:02+00:00] INFO: Processing service[consul-template] action start (consul-template::service line 98)
[2017-08-21T16:38:02+00:00] INFO: libarchive_file[consul-template_0.19.0_linux_amd64.zip] sending restart action to service[consul-template] (delayed)
[2017-08-21T16:38:02+00:00] INFO: Processing service[consul-template] action restart (consul-template::service line 98)
================================================================================
Error executing action `restart` on resource 'service[consul-template]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of /etc/init.d/consul-template restart ----
STDOUT: Stopping consul-template.............
consul-template not stopped; may still be shutting down or shutdown may have failed
Unable to stop consul-template, will not attempt to start
STDERR:
---- End output of /etc/init.d/consul-template restart ----
Ran /etc/init.d/consul-template restart returned 1
Resource Declaration:
---------------------
# In /chef/local-mode-cache/cache/cookbooks/consul-template/recipes/service.rb
98: service 'consul-template' do
99: provider Chef::Provider::Service::Upstart if is_upstart
100: supports status: true, restart: true, reload: true
101: action [:enable, :start]
102: subscribes :restart, "libarchive_file[#{ConsulTemplateHelpers.install_file(node)}]", :delayed
103: end
104:
Compiled Resource:
------------------
# Declared in /chef/local-mode-cache/cache/cookbooks/consul-template/recipes/service.rb:98:in `from_file'
service("consul-template") do
action [:enable, :start]
updated true
supports {:status=>true, :restart=>true, :reload=>true}
retries 0
retry_delay 2
default_guard_interpreter :default
service_name "consul-template"
enabled true
running true
masked nil
pattern "consul-template"
declared_type :service
cookbook_name "consul-template"
recipe_name "service"
end
Platform:
---------
x86_64-linux
[2017-08-21T16:38:13+00:00] ERROR: Running exception handlers
[2017-08-21T16:38:13+00:00] ERROR: Exception handlers complete
[2017-08-21T16:38:13+00:00] FATAL: Stacktrace dumped to /chef/local-mode-cache/cache/chef-stacktrace.out
[2017-08-21T16:38:13+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2017-08-21T16:38:13+00:00] ERROR: service[consul-template] (consul-template::service line 98) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /etc/init.d/consul-template restart ----
STDOUT: Stopping consul-template.............
consul-template not stopped; may still be shutting down or shutdown may have failed
Unable to stop consul-template, will not attempt to start
STDERR:
---- End output of /etc/init.d/consul-template restart ----
Ran /etc/init.d/consul-template restart returned 1
[2017-08-21T16:38:13+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
The Supervisor cookbook depends on the deprecated Python cookbook so indirectly the consul-template cookbook depends on the Python cookbook but I'm pretty sure it doesn't need python.
There are two places in the cookbook that are creating the config dir, and they're setting different permissions...
In the service recipe:
chef-consul-template/recipes/service.rb
Lines 44 to 51 in adda5d8
In the config provider:
chef-consul-template/providers/config.rb
Lines 25 to 32 in adda5d8
I'm guessing that the 0755 that the service recipe sets is probably correct for the directory, and that the config provider should be using that (and just using node['consul_template']['template_mode']
for the template config file). As it is now, the config resource is always setting its changed flag, which is causing our wrapper template to restart consul-template unnecessarily.
depends 'golang', '1.5.0'
Unable to satisfy constraints on package golang due to solution constraint....
Solution constraints that may result in a constraint on golang: [(consul = 0.9.0) -> (golang ~> 1.4)]
The current systemd template fails to cleanly stop (or restart) the CT service on Ubuntu 16.04:
May 24 00:58:41 vagrant-vbox-1 systemd[1]: Stopping Consul Template Daemon...
May 24 00:58:41 vagrant-vbox-1 consul-template[8488]: 2017/05/24 00:58:41.853612 [DEBUG] (cli) receiving signal "terminated"
May 24 00:58:41 vagrant-vbox-1 consul-template[8488]: 2017/05/24 00:58:41.853624 [DEBUG] (cli) receiving signal "continued"
May 24 01:00:12 vagrant-vbox-1 systemd[1]: consul-template.service: State 'stop-sigterm' timed out. Killing.
May 24 01:00:12 vagrant-vbox-1 systemd[1]: consul-template.service: Main process exited, code=killed, status=9/KILL
May 24 01:00:12 vagrant-vbox-1 systemd[1]: Stopped Consul Template Daemon.
It looks like adding a ExecStop
line in consul-template-systemd.erb
solves this issue.
ExecStop=/bin/kill -INT $MAINPID
Ideally the signal would be tied back to the kill_signal
config.
Happy to submit a PR if that helps.
This will allow avoiding template files when they are very trivial.
From CT config:
# This option allows embedding the contents of a template in the configuration
# file rather then supplying the `source` path to the template file. This is
# useful for short templates. This option is mutually exclusive with the
# `source` option.
Right now if source
is missing the resource throws an error.
I think we should upgrade to https://github.com/hashicorp/consul-template/releases/tag/v0.3.1. I'd be happy to help, but is there some easy way to get the checksums for the binary packages?
The cookbook runs successfully, but the service enters failed state:
$ sudo service consul-template status
Redirecting to /bin/systemctl status consul-template.service
● consul-template.service - Consul Template Daemon
Loaded: loaded (/etc/systemd/system/consul-template.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since Mon 2018-02-19 09:14:52 UTC; 35s ago
Process: 26129 ExecStart=/usr/local/bin/consul-template -config /etc/consul-template.d (code=exited, status=14)
Main PID: 26129 (code=exited, status=14)
In case I manually run the comand /usr/local/bin/consul-template -config /etc/consul-template.d
or service consul-template restart
it perfectly works.
OS Centos: 7.3.1611
The cookbook version: 0.12.0
Chef-client: 12.20.3
consul-template: 0.19.4
$ sudo cat /etc/systemd/system/consul-template.service
[Unit]
Description=Consul Template Daemon
Wants=basic.target
After=basic.target network.target
[Service]
User=consul-template
Group=consul-template
ExecStart=/usr/local/bin/consul-template -config /etc/consul-template.d
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
$ sudo cat /etc/consul-template.d/default.json
{
}
$ sudo cat /etc/consul-template.d/haproxy
template {
source = "/etc/haproxy/haproxy.cfg.ctmpl"
destination = "/etc/haproxy/haproxy.cfg"
command = "/bin/bash -c 'systemctl restart haproxy || true'"
}
It would be nice to be able to specify additional options to the CLI command rather than it all in the template file.
When:
/usr/local/bin/consul-template
file does not exist/var/chef/cache/consul-template.zip
file existsThen running chef-client
will result in the /usr/local/bin/consul-template
being created as a zero-length file (and of course, the service[consul-template] will not be running at the end of the chef-run).
This condition is easy to reproduce, just type rm /usr/local/bin/consul-template
on existing setup before running chef-client again.
Here is the relevant portion of my chef-client log (with my comments added):
Recipe: consul-template::install_binary
* ark[consul-template] action cherry_pick
* directory[/usr/local/bin] action create (up to date)
* remote_file[/var/chef/cache/consul-template.zip] action create (up to date)
* execute[cherry_pick consul-template from /var/chef/cache/consul-template.zip] action nothing (skipped due to action :nothing) # <<<<---- this skips extracting consul-template.zip, so /usr/local/bin/consul-template is not created
* execute[set owner on /usr/local/bin] action nothing (skipped due to action :nothing)
(up to date)
* file[/usr/local/bin/consul-template] action touch # <<<<--- this creates the file as a zero-length file
- create new file /usr/local/bin/consul-template
- change mode from '' to '0755'
- update utime on file /usr/local/bin/consul-template
The archive should be extracted in all cases when /usr/local/bin/consul-template
does not exist.
Since the config has can include tokens for consul and vault, it would suggest marking the resource creating the file as sensitive to prevent leaking this info to chef logs.
Hello,
i have spotted an error while calling this cookbook inside my wrapper cookbook which took me a while to debug. I have been getting the following key error due to a wrong filename search for it's own checksum. The recipe should be searching for the checksum named 'consul-template...' (with a dash in the middle) but instead it's searching 'consul_template...' (with an underscore) which causes it to throw a key not found error.
key not found: "consul_template_0.12.2_linux_amd64"
After a bit of debugging and trying out this cookbook on itself I released that the fix has already been implemented in the master branch but it hasn't been released yet, hence still erroring when calling this via a wrapper cookbook.
Could you please create a new tagged release so that I can call this cookbook successfully?
Thank you
It would probably be useful to have a real README 😅
================================================================================
Recipe Compile Error in /tmp/kitchen/cache/cookbooks/consul-template/attributes/default.rb
================================================================================
NoMethodError
-------------
Undefined method or attribute `data_path' on `node'
Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/consul-template/attributes/default.rb:33:in `from_file'
Relevant File Content:
----------------------
/tmp/kitchen/cache/cookbooks/consul-template/attributes/default.rb:
26: default['consul_template']['template_mode'] = 0600
27:
28: # Config attributes
29: default['consul_template']['config'] = Hash.new
30:
31: # Windows only
32: default['consul_template']['nssm_params'] = {
33>> 'AppDirectory' => data_path,
34: 'AppStdout' => join_path(config_prefix_path, 'stdout.log'),
35: 'AppStderr' => join_path(config_prefix_path, 'error.log'),
36: 'AppRotateFiles' => 1,
37: 'AppRotateOnline' => 1,
38: 'AppRotateBytes' => 20_000_000
39: }
40:
Platform:
---------
x86_64-linux
Consul template does not yet support reloading by sending a HUP signal, hashicorp/consul-template#90. So it also crashes on
notifies :reload, "service[consul-template]", :delayed
For now I think we should remove reload from the init.d script, and from from the list of supported actions in the service definition.
commit 5c957f7 broke compatibility with Chef 12's ruby version by modifying libraries/consul-template_helpers.rb line 25 to use the new .match? method.
I see someone already opened PR 81 which would fix this issue. Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.