Initial IaC setup: Nomad, Consul, Terraform, Ansible

- Ansible roles for Nomad and Consul installation
- Nomad job specs for Traefik and monitoring stack
- Terraform configuration for Nomad job management
- Enterprise naming convention inventory
- HashiCorp stack deployment playbook
This commit is contained in:
2026-02-04 08:52:08 -06:00
commit 3d3c1af237
15 changed files with 998 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
---
- name: Restart Nomad
ansible.builtin.systemd:
name: nomad
state: restarted
daemon_reload: yes
+76
View File
@@ -0,0 +1,76 @@
---
# Nomad Installation Role
- name: Install dependencies
ansible.builtin.apt:
name:
- curl
- gnupg
- lsb-release
- apt-transport-https
state: present
update_cache: yes
- name: Add HashiCorp GPG key
ansible.builtin.apt_key:
url: https://apt.releases.hashicorp.com/gpg
state: present
- name: Add HashiCorp repository
ansible.builtin.apt_repository:
repo: "deb https://apt.releases.hashicorp.com {{ ansible_distribution_release }} main"
state: present
filename: hashicorp
- name: Install Nomad
ansible.builtin.apt:
name: "nomad={{ nomad_version }}-1"
state: present
update_cache: yes
- name: Create Nomad directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: nomad
group: nomad
mode: '0755'
loop:
- "{{ nomad_data_dir }}"
- "{{ nomad_data_dir }}/data"
- /etc/nomad.d
- name: Configure Nomad
ansible.builtin.template:
src: nomad.hcl.j2
dest: /etc/nomad.d/nomad.hcl
owner: nomad
group: nomad
mode: '0640'
notify: Restart Nomad
- name: Configure Nomad server (if server)
ansible.builtin.template:
src: server.hcl.j2
dest: /etc/nomad.d/server.hcl
owner: nomad
group: nomad
mode: '0640'
when: nomad_server | default(false)
notify: Restart Nomad
- name: Configure Nomad client
ansible.builtin.template:
src: client.hcl.j2
dest: /etc/nomad.d/client.hcl
owner: nomad
group: nomad
mode: '0640'
when: nomad_client | default(false)
notify: Restart Nomad
- name: Enable and start Nomad
ansible.builtin.systemd:
name: nomad
enabled: yes
state: started
@@ -0,0 +1,34 @@
# Nomad Client Configuration
client {
enabled = true
node_class = "{{ nomad_node_class | default('default') }}"
# Resource reservations
reserved {
cpu = 500
memory = 512
}
# Host volumes for persistent data
host_volume "docker-data" {
path = "/mnt/nas/docker"
read_only = false
}
host_volume "media" {
path = "/mnt/nas/media"
read_only = false
}
# Meta information
meta {
"rack" = "{{ rack | default('rack-1') }}"
"datacenter" = "{{ datacenter }}"
"legacy_name" = "{{ legacy_name | default('unknown') }}"
}
# Network interface
network_interface = "{{ ansible_default_ipv4.interface | default('eth0') }}"
}
@@ -0,0 +1,53 @@
# Nomad Configuration
# Managed by Ansible - Do not edit manually
datacenter = "{{ datacenter }}"
data_dir = "{{ nomad_data_dir }}/data"
bind_addr = "0.0.0.0"
advertise {
http = "{{ ansible_host }}"
rpc = "{{ ansible_host }}"
serf = "{{ ansible_host }}"
}
# Enable ACLs (after bootstrap)
# acl {
# enabled = true
# }
# Consul integration
consul {
address = "127.0.0.1:8500"
server_service_name = "nomad"
client_service_name = "nomad-client"
auto_advertise = true
server_auto_join = true
client_auto_join = true
}
# Vault integration (after Vault setup)
# vault {
# enabled = true
# address = "http://127.0.0.1:8200"
# }
telemetry {
collection_interval = "10s"
disable_hostname = true
prometheus_metrics = true
publish_allocation_metrics = true
publish_node_metrics = true
}
plugin "docker" {
config {
allow_privileged = true
volumes {
enabled = true
}
extra_labels = ["job_name", "task_group_name", "task_name", "namespace", "node_name"]
}
}
@@ -0,0 +1,14 @@
# Nomad Server Configuration
server {
enabled = true
bootstrap_expect = {{ nomad_bootstrap_expect | default(1) }}
# Raft settings
raft_protocol = 3
# Server join (for multi-server setup)
# server_join {
# retry_join = ["hf-pdocker-01.hobbs.farm"]
# }
}