Deploy `nomad`.

This commit is contained in:
Kazuhiro MUSASHI 2021-04-30 14:50:09 +09:00
parent 70c90a18e2
commit 010a53a58b
13 changed files with 152 additions and 1 deletions

View File

@ -10,7 +10,7 @@ end
DIST = run_command('lsb_release -cs').stdout.chomp
# Deploy the `apt` sources:
template '/etc/apt/sources.list.d/consul.list' do
template '/etc/apt/sources.list.d/hashicorp.list' do
action :create
variables(distribution: DIST)
end

View File

@ -0,0 +1,9 @@
# -------------------------------------------
# Specifying the default settings:
# -------------------------------------------
node.reverse_merge!({
'nomad' => {
'manager' => false,
'client' => true
}
})

View File

@ -0,0 +1,7 @@
include_recipe './attributes.rb'
include_recipe './install.rb'
include_recipe './setup.rb'
include_recipe './shared_dir.rb'

View File

@ -0,0 +1,13 @@
# /etc/nomad.d/server.hcl
client {
enabled = true
}
plugin "docker" {
config {
volumes {
enabled = true
}
}
}

View File

@ -0,0 +1,4 @@
# /etc/nomad.d/server.hcl
# data_dir tends to be environment specific.
data_dir = "/opt/nomad/data/"

View File

@ -0,0 +1,6 @@
client {
host_volume "docker-registry" {
path = "/mnt/shared/Docker-registry"
read_only = false
}
}

View File

@ -0,0 +1,4 @@
server {
enabled = true
bootstrap_expect = 3
}

View File

@ -0,0 +1,3 @@
net.bridge.bridge-nf-call-arptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

View File

@ -0,0 +1,20 @@
# Install `Consul`:
KEYSRV = "https://apt.releases.hashicorp.com/gpg"
ID = "A3219F7B"
execute "apt-key adv --keyserver #{KEYSRV} --recv-keys #{ID}" do
not_if 'apt-key list | grep HashiCorp'
end
# Retrieve the Ubuntu code:
DIST = run_command('lsb_release -cs').stdout.chomp
# Deploy the `apt` sources:
template '/etc/apt/sources.list.d/hashicorp.list' do
action :create
variables(distribution: DIST)
end
execute 'apt update'
package 'nomad'

65
cookbooks/nomad/setup.rb Normal file
View File

@ -0,0 +1,65 @@
# Kernel parameters:
remote_file '/etc/sysctl.d/90-nomad.conf' do
owner 'root'
group 'root'
mode '0644'
end
# nomad configuration files:
file '/etc/nomad.d/nomad.hcl' do
action :delete
end
remote_file '/etc/nomad.d/datadir.hcl' do
owner 'nomad'
group 'nomad'
mode '664'
notifies :restart, 'service[nomad]'
end
if node['nomad']['manager']
remote_file '/etc/nomad.d/server.hcl' do
owner 'nomad'
group 'nomad'
mode '664'
notifies :restart, 'service[nomad]'
end
end
if node['nomad']['client']
%w( /etc/nomad.d/client.hcl /etc/nomad.d/docker-registry.hcl ).each do |conf|
remote_file conf do
owner 'nomad'
group 'nomad'
mode '664'
notifies :restart, 'service[nomad]'
end
end
end
# Create directory:
directory '/opt/nomad/data/' do
owner 'nomad'
group 'nomad'
mode '0755'
end
# iptables settings here:
%w( 80/tcp 4646/tcp 4647/tcp 4648/tcp 8081/tcp 20000:32000/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
# Enable and start nomad:
service 'nomad' do
action [:enable, :start]
end

View File

@ -0,0 +1,19 @@
%w( /mnt/shared ).each do |d|
directory d do
owner 'root'
group 'root'
end
end
# Add the fstab entry:
file '/etc/fstab' do
action :edit
block do |content|
content << "//192.168.10.200/Shared/AppData /mnt/shared cifs username=admin,password=Holiday88,uid=root,gid=root,file_mode=0777,dir_mode=0777,vers=3.0,_netdev 0 0\n"
end
not_if 'grep shared /etc/fstab'
end
execute 'mount -a || true'

View File

@ -0,0 +1 @@
deb [arch=amd64] https://apt.releases.hashicorp.com <%= @distribution %> main