Deploy backup jobs to all hosts and dynamically determine jobs per node

This commit is contained in:
IamTheFij 2022-06-23 09:49:57 -07:00
parent 325a27a4ec
commit d022fe9bc4
2 changed files with 28 additions and 34 deletions

View File

@ -5,10 +5,15 @@ variable "nextcloud_backup" {
job "backup" { job "backup" {
datacenters = ["dc1"] datacenters = ["dc1"]
type = "service" type = "system"
group "nomad0" { constraint {
count = 1 attribute = "${node.unique.name}"
# Only node with a backup job so far
value = "n2"
}
group "backup" {
network { network {
mode = "bridge" mode = "bridge"
@ -18,22 +23,10 @@ job "backup" {
} }
} }
volume "nextcloud-data" { volume "all-volumes" {
type = "host" type = "host"
read_only = true read_only = true
source = "nextcloud-data" source = "all-volumes"
}
volume "gitea-data" {
type = "host"
read_only = true
source = "gitea-data"
}
volume "authentik-data" {
type = "host"
read_only = true
source = "authentik-data"
} }
service { service {
@ -73,20 +66,8 @@ job "backup" {
driver = "docker" driver = "docker"
volume_mount { volume_mount {
volume = "nextcloud-data" volume = "all-volumes"
destination = "/data/nextcloud" destination = "/data"
read_only = true
}
volume_mount {
volume = "gitea-data"
destination = "/data/gitea"
read_only = true
}
volume_mount {
volume = "authentik-data"
destination = "/data/authentik"
read_only = true read_only = true
} }
@ -94,7 +75,7 @@ job "backup" {
image = "iamthefij/resticscheduler" image = "iamthefij/resticscheduler"
ports = ["metrics"] ports = ["metrics"]
args = [ args = [
"/jobs/nextcloud.hcl", "/jobs/node-jobs.hcl",
] ]
mount { mount {
@ -117,8 +98,15 @@ job "backup" {
} }
template { template {
data = var.nextcloud_backup data = <<EOF
destination = "jobs/nextcloud.hcl" # Current node is {{ env "node.unique.name" }}
{{ range service "nextcloud" }}
# Nextcloud .Node {{ .Node }}
{{ if eq .Node (env "node.unique.name") }}
${var.nextcloud_backup}
{{ end }}{{ end }}
EOF
destination = "jobs/node-jobs.hcl"
} }
resources { resources {

View File

@ -205,6 +205,12 @@
group: "root" group: "root"
mode: "0777" mode: "0777"
read_only: true read_only: true
- name: all-volumes
path: /srv/volumes
owner: "root"
group: "root"
mode: "0777"
read_only: false
roles: roles:
- name: ansible-nomad - name: ansible-nomad