itamae/cookbooks/consul/setup.rb

56 lines
1.0 KiB
Ruby
Raw Normal View History

2020-11-22 08:25:09 +00:00
if node['consul']['manager']
SRC = 'consul-server.hcl.erb'
else
SRC = 'consul-agent.hcl.erb'
end
template '/etc/consul.d/consul.hcl' do
2020-11-22 07:00:00 +00:00
owner 'consul'
group 'consul'
2019-03-03 08:50:49 +00:00
mode '644'
variables(manager: node['consul']['manager'],
manager_hosts: node['consul']['manager_hosts'],
ipaddr: node['consul']['ipaddr'],
)
2020-11-22 08:25:09 +00:00
source "templates/etc/consul.d/#{SRC}"
notifies :restart, 'service[consul]'
2019-03-03 08:50:49 +00:00
end
2020-11-22 14:26:05 +00:00
directory '/var/log/consul/' do
owner 'consul'
group 'consul'
mode '0755'
end
remote_file '/etc/systemd/system/consul.service' do
owner 'root'
group 'root'
mode '0644'
notifies :restart, 'service[consul]'
end
2019-03-03 08:50:49 +00:00
remote_file '/etc/consul.d/service-consul.json' do
2020-11-22 07:00:00 +00:00
owner 'consul'
group 'consul'
2019-03-03 08:50:49 +00:00
mode '644'
end
service 'consul' do
action [:enable, :start]
end
2019-03-03 08:50:49 +00:00
# iptables settings here:
%w( 8300/tcp 8301/tcp 8301/udp 8500/tcp ).each do |port|
execute "ufw allow #{port}" do
user 'root'
not_if "LANG=c ufw status | grep #{port}"
notifies :run, 'execute[ufw reload-or-enable]'
end
end