From b2c03f1e60e9bd1b78452f30b99079f47ef905f5 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Sat, 12 Mar 2022 10:07:52 -0800 Subject: [PATCH] Update hosts improve bootstrap and move a few things around --- nomad/Makefile | 3 +- nomad/ansible_hosts.yml | 10 +- nomad/docker-setup.yaml | 47 +++++ nomad/metrics/grafana.nomad | 124 +++++++++++++ nomad/metrics/metrics.tf | 39 ++-- nomad/metrics/prometheus.nomad | 3 +- nomad/packer/cloud-config | 85 +++++++++ ...oud-init.hcl => ubuntu-cloud-init.pkr.hcl} | 18 +- nomad/services.tf | 26 +-- nomad/setup-cluster.yml | 168 +++++++++++------- nomad/traefik/traefik.nomad | 2 +- nomad/whoami.nomad | 5 - 12 files changed, 411 insertions(+), 119 deletions(-) create mode 100644 nomad/docker-setup.yaml create mode 100644 nomad/metrics/grafana.nomad create mode 100644 nomad/packer/cloud-config rename nomad/packer/{ubuntu-cloud-init.hcl => ubuntu-cloud-init.pkr.hcl} (51%) diff --git a/nomad/Makefile b/nomad/Makefile index 69bfb89..7ede4e2 100644 --- a/nomad/Makefile +++ b/nomad/Makefile @@ -56,10 +56,11 @@ cluster: consul-up nomad-up venv/bin/ansible: python3 -m venv venv ./venv/bin/pip install ansible + ./venv/bin/pip install python-consul .PHONY: ansible-cluster ansible-cluster: venv/bin/ansible - ./venv/bin/ansible-galaxy install -p ansible_roles -r roles/requirements.yml + ./venv/bin/ansible-galaxy install -p roles -r roles/requirements.yml ./venv/bin/ansible-playbook -K -vv -i ansible_hosts.yml -M ./roles ./setup-cluster.yml .PHONY: plan diff --git a/nomad/ansible_hosts.yml b/nomad/ansible_hosts.yml index 7d39179..83081a5 100644 --- a/nomad/ansible_hosts.yml +++ b/nomad/ansible_hosts.yml @@ -3,14 +3,13 @@ all: children: servers: hosts: - services.thefij: - consul_node_role: bootstrap + nomad0.thefij: + # consul_node_role: bootstrap nomad_node_role: both - nomad_node_class: ingress nomad_host_volumes: - name: mysql-data path: /srv/volumes/mysql-data - owner: "nomad" + owner: "root" group: "bin" mode: "0755" read_only: false @@ -19,6 +18,9 @@ all: # dns_san: ["services.thefij"] # ip_san: ["192.168.2.41", "127.0.0.1"] # motionpi.thefij: {} + nomad1.thefij: + nomad_node_class: ingress + nomad_node_role: both consul_instances: children: diff --git a/nomad/docker-setup.yaml b/nomad/docker-setup.yaml new file mode 100644 index 0000000..06c8817 --- /dev/null +++ b/nomad/docker-setup.yaml @@ -0,0 +1,47 @@ +--- +- name: Setup Docker on host + hosts: docker_hosts + vars: + user_name: "{{ create_user | default(ansible_user) }}" + docker_config_path: >- + {% if ansible_facts.os_family == 'Darwin' -%} + ~/.docker/daemon.json + {%- else -%} + /etc/docker/daemon.json + {%- endif %} + ansible_python_interpreter: python3 + + roles: + - docker_install + + tasks: + + - name: Add to Docker group + user: + name: "{{ user_name }}" + groups: docker + append: true + become: true + + - name: Use journald logging driver # noqa 207 + json_merge: + path: "{{ docker_config_path }}" + allow_create: true + format_indent: true + update_json: { + "log-driver": "journald", + "log-opts": { + "tag": "{{ '{{ .Name }}/{{ .ImageName }}/{{ .ID }}' }}", + "labels": "com.docker.compose.project,com.docker.compose.service" + } + } + become: true + notify: Restart Docker daemon + + handlers: + - name: Restart Docker daemon + service: + name: docker + state: restarted + become: true + when: ansible_facts['os_family'] != "Darwin" diff --git a/nomad/metrics/grafana.nomad b/nomad/metrics/grafana.nomad new file mode 100644 index 0000000..ef096ce --- /dev/null +++ b/nomad/metrics/grafana.nomad @@ -0,0 +1,124 @@ +job "grafana" { + datacenters = ["dc1"] + + group "grafana" { + count = 1 + + network { + mode = "bridge" + + port "web" { + host_network = "loopback" + to = 3000 + } + } + + service { + port = "web" + + connect { + sidecar_service { + proxy { + local_service_port = 3000 + + upstreams { + destination_name = "prometheus" + local_bind_port = 9090 + } + } + } + + sidecar_task { + resources { + cpu = 50 + memory = 50 + } + } + } + + check { + type = "http" + path = "/" + port = "web" + interval = "10s" + timeout = "10s" + } + + tags = [ + "traefik.enable=true", + "traefik.http.routers.grafana.entrypoints=web,websecure", + "traefik.http.routers.grafana.rule=Host(`grafana.dev.homelab`)", + "traefik.subdomain=grafana-sub", + "traefik.http.routers.grafana.tls=true", + ] + } + + task "grafana" { + driver = "docker" + + config { + image = "grafana/grafana:7.3.6" + ports = ["web"] + + mount { + type = "bind" + target = "/etc/grafana/grafana.ini" + source = "local/config/grafana.ini" + } + + mount { + type = "bind" + target = "/etc/grafana/provisioning" + source = "local/config/provisioning" + } + } + + env = { + "GF_SECURITY_ADMIN_PASSWORD" = "password", + "GF_INSTALL_PLUGINS" = "grafana-clock-panel,grafana-piechart-panel,grafana-polystat-panel", + } + + template { + data = <