From 885907310f2e245059d2517a1c0473c265182cdf Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 6 Apr 2024 16:40:01 +0900 Subject: [PATCH 1/3] Deploy `/etc/nomad.d/client.hcl`. --- cookbooks/nomad/setup.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cookbooks/nomad/setup.rb b/cookbooks/nomad/setup.rb index 3a26a5f..100a9b3 100644 --- a/cookbooks/nomad/setup.rb +++ b/cookbooks/nomad/setup.rb @@ -38,11 +38,13 @@ end if node['nomad']['client'] %w( /etc/nomad.d/client.hcl ).each do |conf| - remote_file conf do + template conf do owner 'nomad' group 'nomad' mode '664' + variables(consul-token: node['nomad']['consul-token']) + notifies :restart, 'service[nomad]' end end From b91b44908b0e091db427d5c1250b45f4b6926bd4 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 6 Apr 2024 16:44:55 +0900 Subject: [PATCH 2/3] Deploy `/etc/nomad.d/options.hcl`. --- cookbooks/nomad/files/etc/nomad.d/options.hcl | 23 +++++++++++++++++++ cookbooks/nomad/setup.rb | 8 +++++++ 2 files changed, 31 insertions(+) create mode 100644 cookbooks/nomad/files/etc/nomad.d/options.hcl diff --git a/cookbooks/nomad/files/etc/nomad.d/options.hcl b/cookbooks/nomad/files/etc/nomad.d/options.hcl new file mode 100644 index 0000000..514aec8 --- /dev/null +++ b/cookbooks/nomad/files/etc/nomad.d/options.hcl @@ -0,0 +1,23 @@ +plugin "docker" { + config { + # extra Docker labels to be set by Nomad on each Docker container with the appropriate value + extra_labels = ["job_name", "task_group_name", "task_name", "namespace", "node_name"] + + volumes { + enabled = true + } + + allow_privileged = true + } +} + +client { + host_volume "docker-sock" { + path = "/var/run/docker.sock" + } + + host_volume "tmp" { + path = "/tmp" + } +} + diff --git a/cookbooks/nomad/setup.rb b/cookbooks/nomad/setup.rb index 100a9b3..4aff591 100644 --- a/cookbooks/nomad/setup.rb +++ b/cookbooks/nomad/setup.rb @@ -49,6 +49,14 @@ if node['nomad']['client'] end end + remote_file "/etc/nomad.d/options.hcl" do + mode "0644" + owner "nomad" + group "nomad" + + notifies :restart, 'service[nomad]' + end + directory '/etc/nomad.d/jobs' do owner 'nomad' group 'nomad' From ddc85e470440f9347f61584695ca75c9df6fe426 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 6 Apr 2024 16:38:09 +0900 Subject: [PATCH 3/3] Populate `consul`'s token. --- cookbooks/nomad/attributes.rb | 1 + cookbooks/nomad/setup.rb | 2 +- cookbooks/nomad/{files => templates}/etc/nomad.d/client.hcl | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) rename cookbooks/nomad/{files => templates}/etc/nomad.d/client.hcl (55%) diff --git a/cookbooks/nomad/attributes.rb b/cookbooks/nomad/attributes.rb index e366ebf..7f51ab1 100644 --- a/cookbooks/nomad/attributes.rb +++ b/cookbooks/nomad/attributes.rb @@ -5,6 +5,7 @@ node.reverse_merge!({ 'nomad' => { 'manager' => false, 'client' => false, + 'consul_token' => "f1d577dc-9216-d72a-cc09-1962b1009273", 'lokiendpoint' => 'loki.service.consul:3100', 'synology' => '192.168.10.200' } diff --git a/cookbooks/nomad/setup.rb b/cookbooks/nomad/setup.rb index 4aff591..0f8ceb0 100644 --- a/cookbooks/nomad/setup.rb +++ b/cookbooks/nomad/setup.rb @@ -43,7 +43,7 @@ if node['nomad']['client'] group 'nomad' mode '664' - variables(consul-token: node['nomad']['consul-token']) + variables(consul_token: node['nomad']['consul_token']) notifies :restart, 'service[nomad]' end diff --git a/cookbooks/nomad/files/etc/nomad.d/client.hcl b/cookbooks/nomad/templates/etc/nomad.d/client.hcl similarity index 55% rename from cookbooks/nomad/files/etc/nomad.d/client.hcl rename to cookbooks/nomad/templates/etc/nomad.d/client.hcl index dd7b407..cb39006 100644 --- a/cookbooks/nomad/files/etc/nomad.d/client.hcl +++ b/cookbooks/nomad/templates/etc/nomad.d/client.hcl @@ -6,6 +6,6 @@ client { } } -# consul { -# token = "11800359-1330-fe54-d858-44e8de9a14f6" -# } +consul { + token = "<%= @consul_token %>" +}