Deploy `consul-template`.
This commit is contained in:
parent
010a53a58b
commit
2eed57822c
|
@ -0,0 +1,13 @@
|
||||||
|
# -------------------------------------------
|
||||||
|
# Specifying the default settings:
|
||||||
|
# -------------------------------------------
|
||||||
|
node.reverse_merge!({
|
||||||
|
'consulTemplate' => {
|
||||||
|
'baseUrl' => 'https://releases.hashicorp.com/consul-template/',
|
||||||
|
'version' => '0.25.2',
|
||||||
|
'zipPrefix' => 'consul-template_',
|
||||||
|
'zipPostfix' => '_linux_amd64.zip',
|
||||||
|
'storage' => '/opt/consul-template/consul-template',
|
||||||
|
'location' => '/usr/local/bin/consul-template'
|
||||||
|
},
|
||||||
|
})
|
|
@ -0,0 +1,7 @@
|
||||||
|
# Loading the attributes:
|
||||||
|
include_recipe './attributes.rb'
|
||||||
|
|
||||||
|
# Install loki here:
|
||||||
|
include_recipe './install.rb'
|
||||||
|
include_recipe './setup.rb'
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
OPTIONS="-syslog -syslog-name=consul-template"
|
|
@ -0,0 +1,7 @@
|
||||||
|
# Log kernel generated promtail log messages to file
|
||||||
|
:syslogtag,contains,"consul-template" /var/log/consul-template.log
|
||||||
|
|
||||||
|
# Uncomment the following to stop logging anything that matches the last rule.
|
||||||
|
# Doing this will stop logging kernel generated UFW log messages to the file
|
||||||
|
# normally containing kern.* messages (eg, /var/log/kern.log)
|
||||||
|
& stop
|
|
@ -0,0 +1,13 @@
|
||||||
|
[Unit]
|
||||||
|
Description=consul-template
|
||||||
|
Requires=network-online.target
|
||||||
|
After=network-online.target consul.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
EnvironmentFile=-/etc/default/consul-template
|
||||||
|
Restart=on-failure
|
||||||
|
ExecStart=/usr/local/bin/consul-template $OPTIONS -config=/etc/consul-template.d/conf/
|
||||||
|
KillSignal=SIGINT
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -0,0 +1,34 @@
|
||||||
|
consulTemplate_zip = "#{node['consulTemplate']['zipPrefix']}#{node['consulTemplate']['version']}#{node['consulTemplate']['zipPostfix']}"
|
||||||
|
consulTemplate_url = "#{node['consulTemplate']['baseUrl']}#{node['consulTemplate']['version']}/#{consulTemplate_zip}"
|
||||||
|
|
||||||
|
# バージョン確認して、アップデート必要かどうか確認
|
||||||
|
result = run_command('which consul-template', error: false)
|
||||||
|
if result.exit_status != 0
|
||||||
|
|
||||||
|
# Download:
|
||||||
|
TMP = "/tmp/#{consulTemplate_zip}"
|
||||||
|
|
||||||
|
execute "wget #{consulTemplate_url} -O #{TMP}"
|
||||||
|
|
||||||
|
directory '/opt/consul-template' do
|
||||||
|
owner 'root'
|
||||||
|
group 'root'
|
||||||
|
mode '0755'
|
||||||
|
end
|
||||||
|
|
||||||
|
execute "unzip #{TMP} -d /opt/consul-template/" do
|
||||||
|
not_if 'test -e /opt/consul-template/consul-template'
|
||||||
|
end
|
||||||
|
|
||||||
|
# Change Owner and Permissions:
|
||||||
|
file "#{node['consulTemplate']['storage']}" do
|
||||||
|
owner 'root'
|
||||||
|
group 'root'
|
||||||
|
mode '755'
|
||||||
|
end
|
||||||
|
|
||||||
|
# Create Link
|
||||||
|
link "#{node['consulTemplate']['location']}" do
|
||||||
|
to "#{node['consulTemplate']['storage']}"
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,39 @@
|
||||||
|
# Create `/var/log/vector`:
|
||||||
|
%w( /etc/consul-template.d/conf /etc/consul-template.d/templates ).each do |d|
|
||||||
|
directory d do
|
||||||
|
owner 'root'
|
||||||
|
group 'root'
|
||||||
|
mode '0755'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
%w( /etc/systemd/system/consul-template.service /etc/default/consul-template).each do |conf|
|
||||||
|
remote_file conf do
|
||||||
|
owner 'root'
|
||||||
|
group 'root'
|
||||||
|
mode '0644'
|
||||||
|
|
||||||
|
notifies :run, 'execute[systemctl daemon-reload]', :immediately
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
execute 'systemctl daemon-reload' do
|
||||||
|
action :nothing
|
||||||
|
end
|
||||||
|
|
||||||
|
service 'consul-template' do
|
||||||
|
action [:enable, :restart]
|
||||||
|
end
|
||||||
|
|
||||||
|
remote_file '/etc/rsyslog.d/30-consul-template.conf' do
|
||||||
|
owner 'root'
|
||||||
|
group 'root'
|
||||||
|
mode '0644'
|
||||||
|
|
||||||
|
notifies :restart, 'service[rsyslog]', :immediately
|
||||||
|
end
|
||||||
|
|
||||||
|
service 'rsyslog' do
|
||||||
|
action [ :nothing ]
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue