Skip to content

Commit

Permalink
Update and extend config templates
Browse files Browse the repository at this point in the history
  • Loading branch information
G. Roggemans committed Jun 18, 2017
1 parent dd042fa commit 8828144
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 61 deletions.
62 changes: 57 additions & 5 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# File: main.yml - Main default variables for nomad

## Core
nomad_debug: no

### Package
nomad_version: "{{ lookup('env','NOMAD_VERSION') | default('0.5.6', true) }}"
Expand Down Expand Up @@ -35,16 +36,67 @@ nomad_group: "bin"
nomad_datacenter: "dc1"
nomad_region: "global"
nomad_log_level: "INFO"
nomad_syslog_enable: "true"
nomad_iface: "{{ lookup('env','NOMAD_IFACE') | default('eth1', true) }}"
nomad_syslog_enable: yes
nomad_iface: "{{ lookup('env','NOMAD_IFACE') | default(ansible_default_ipv4.interface, true) }}"
nomad_node_name: "{{ inventory_hostname_short }}"
nomad_node_role: "{{ lookup('env','NOMAD_NODE_ROLE') | default('client', true) }}"
nomad_leave_on_terminate: yes
nomad_leave_on_interrupt: no
nomad_disable_update_check: no

#### Server settings
nomad_retry_max: 0
nomad_retry_join: no
nomad_retry_interval: "30s"
nomad_rejoin_after_leave: no
nomad_enabled_schedulers:
- service
- batch
- system
nomad_node_gc_threshold: "24h"
nomad_job_gc_threshold: "4h"
nomad_eval_gc_threshold: "1h"
nomad_num_schedulers: {{ ansible_processor_vcpus }}
nomad_encrypt: ""

#### Client settings
nomad_node_class: ""
nomad_no_host_uuid: no
nomad_max_kill_timeout: "30s"
nomad_network_speed: 0
nomad_cpu_total_compute: 0
nomad_gc_interval: "1m"
nomad_gc_disk_usage_threshold: 80
nomad_gc_inode_usage_threshold: 70
nomad_gc_parallel_destroys: 2
nomad_reserved:
cpu: {{ nomad_reserved_cpu | default('0', true) }}
memory: {{ nomad_reserved_memory | default('0', true) }}
disk: {{ nomad_reserved_disk | default('0', true) }}
ports: "{{ nomad_reserved_ports | default('22,8500-8600', true) }}"

### Addresses
nomad_advertise_address: "{{ hostvars[inventory_hostname]['ansible_'+nomad_iface]['ipv4']['address'] }}"
nomad_bind_address: "0.0.0.0"
nomad_bind_address: "{{ hostvars[inventory_hostname]['ansible_'+ nomad_iface ]['ipv4']['address'] }}"
nomad_advertise_address: "{{ hostvars[inventory_hostname]['ansible_' + nomad_iface]['ipv4']['address'] }}"

### Ports
nomad_ports:
http: "{{ nomad_ports_http | default('4646', true) }}"
rpc: "{{ nomad_ports_rpc | default('4647', true) }}"
serf: "{{ nomad_ports_serf | default('4648', true) }}"

### Servers
nomad_group_name: "cluster_nodes"
nomad_server_count: "2"
nomad_servers: "\
{% set _nomad_servers = [] %}\
{% for host in groups[nomad_group_name] %}\
{% set _nomad_node_role = hostvars[host]['nomad_node_role'] | default('client', true) %}\
{% if ( _nomad_node_role == 'server' or _nomad_node_role == 'both') %}\
{% if _nomad_servers.append(host) %}{% endif %}\
{% endif %}\
{% endfor %}\
{{ _nomad_servers }}"
nomad_gather_server_facts: no

### Consul
nomad_use_consul: False
Expand Down
16 changes: 16 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
- name: Include OS variables
include_vars: "{{ ansible_os_family }}.yml"

# Gathers facts (bind address) from servers not currently targeted.
# 'delegate_facts' is currently rather buggy in Ansible so this might not
# always work. Hence 'nomad_gather_server_facts' defaults to 'no'.
- name: Gather facts from other servers
setup:
delegate_to: "{{ item }}"
delegate_facts: True
with_items: "{{ nomad_servers | difference(play_hosts) }}"
ignore_errors: yes
when: nomad_gather_server_facts | bool

- name: Expose bind_address and node_role as facts
set_fact:
nomad_bind_address: "{{ nomad_bind_address }}"
nomad_node_role: "{{ nomad_node_role }}"

- name: Include user and group settings
include: user_group.yml

Expand Down
44 changes: 16 additions & 28 deletions templates/base.hcl.j2
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
# Base Nomad configuration, based on:
# https://www.nomadproject.io/docs/cluster/bootstrapping.html

# Name the region, if omitted, the default "global" region will be used.
name = "{{ nomad_node_name }}"
region = "{{ nomad_region }}"

# Name the datacenter, if omitted, the default "dc1" datacenter will be used.
datacenter = "{{ nomad_datacenter }}"

# Persist data to a location that will survive a machine reboot.
data_dir = "{{ nomad_data_dir }}"
enable_debug = {{ nomad_debug | bool | lower }}
disable_update_check = {{ nomad_disable_update_check | bool | lower }}

# Bind to all addresses so that the Nomad agent is available
# both on loopback and externally.
bind_addr = "{{ nomad_bind_address }}"

# Advertise an accessible IP address so the server is reachable by
# other servers and clients. The IPs can be materialized by Terraform
# or be replaced by an init script.

advertise {
http = "{{ nomad_advertise_address }}:4646"
rpc = "{{ nomad_advertise_address }}:4647"
serf = "{{ nomad_advertise_address }}:4648"
http = "{{ nomad_advertise_address }}"
rpc = "{{ nomad_advertise_address }}"
serf = "{{ nomad_advertise_address }}"
}
ports {
http = {{ nomad_ports['http'] }}
rpc = {{ nomad_ports['rpc'] }}
serf = {{ nomad_ports['serf'] }}
}

# Send Nomad telemetry to statsite

# telemetry {
# statsite_address = "${var.statsite}"
# disable_hostname = true
# }
data_dir = "{{ nomad_data_dir }}"

# Enable debug endpoints
enable_debug = true
log_level = "{{ nomad_log_level }}"
enable_syslog = {{ nomad_syslog_ enable | bool | lower }}

# Graceful leave on SIGTERM
leave_on_terminate = true
leave_on_terminate = {{ nomad_leave_on_terminate | bool | lower }}
leave_on_interrupt = {{ nomad_leave_on_interrupt | bool | lower }}
36 changes: 25 additions & 11 deletions templates/client.hcl.j2
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# Nomad client configuration
# Based on: https://www.nomadproject.io/docs/cluster/bootstrapping.html
client {
enabled = {{ nomad_node_client | bool | lower }}

# Enable the client
node_class = "{{ nomad_node_class }}"
no_host_uuid = {{ nomad_no_host_uuid | bool | lower }}

client {
enabled = true
{% if nomad_use_consul == False %}
#use dns discovery to find nomad service directly instead of native consul
servers = ["nomad.service.consul:4647"]
{% endif %}
servers = [
{% for server in _nomad_servers -%}
{% set comma = joiner(",") %}
{{ comma }}"{{ hostvars[server]['nomad_advertise_address'] | ipwrap }}"
{%- endfor -%} ]

max_kill_timeout = "{{ nomad_max_kill_timeout }}"

network_speed = {{ nomad_network_speed }}
cpu_total_compute = {{ nomad_cpu_total_compute }}

gc_interval = "{{ nomad_gc_interval }}"
gc_disk_usage_threshold = {{ nomad_gc_disk_usage_threshold }}
gc_inode_usage_threshold = {{ nomad_gc_inode_usage_threshold }}
gc_parallel_destroys = {{ nomad_gc_parallel_destroys }}

reserved {
cpu = {{ nomad_reserved['cpu'] }}
memory = {{ nomad_reserved['memory'] }}
disk = {{ nomad_reserved['disk'] }}
ports = {{ nomad_reserved['ports'] }}
}
}
# Increase log verbosity
log_level = "{{nomad_log_level}}"
51 changes: 34 additions & 17 deletions templates/server.hcl.j2
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
{% set comma = joiner(",") %}
{% set lbracket = "[" %}
{% set rbracket = "]" %}
{% set quote = '"' %}

# Enable the server
server {
enabled = true
bootstrap_expect = {{ nomad_server_count }}
{% if nomad_use_consul == False %}
start_join= {{ lbracket }}{% for host in groups['cluster_nodes'] %}{% if hostvars[inventory_hostname]['ansible_default_ipv4']['address'] != hostvars[host]['ansible_default_ipv4']['address'] %}{{ comma() }}{{ quote }}{{ hostvars[host]['ansible_default_ipv4']['address'] }}{{ quote }}{% endif %}
{% endfor %}{{ rbracket }}
retry_join= {{ lbracket }}{% for host in groups['cluster_nodes'] %}{% if hostvars[inventory_hostname]['ansible_default_ipv4']['address'] != hostvars[host]['ansible_default_ipv4']['address'] %}{{ comma() }}{{ quote }}{{ hostvars[host]['ansible_default_ipv4']['address'] }}{{ quote }}{% endif %}
{% endfor %}{{ rbracket }}
retry_interval = "15s"
{% endif %}
enabled = {{ nomad_node_server | bool | lower }}

bootstrap_expect = {{ _nomad_servers | count }}

{% if nomad_retry_join | bool -%}
retry_join = [
{% for server in _nomad_servers -%}
{% set comma = joiner(",") %}
{{ comma }}"{{ hostvars[server]['nomad_advertise_address'] | ipwrap }}"
{%- endfor -%} ]
retry_max = {{ nomad_retry_max }}
retry_interval = "{{ nomad_retry_interval }}"
{% else %}
start_join = [
{% for server in _nomad_servers -%}
{% set comma = joiner(",") %}
{{ comma }}"{{ hostvars[server]['nomad_advertise_address'] | ipwrap }}"
{%- endfor -%} ]
{%- endif %}

rejoin_after_leave = {{ nomad_rejoin_after_leave | bool | lower }}

enabled_schedulers = [
{% for scheduler in nomad_enabled_schedulers -%}
{% set comma = joiner(",") %}
{{ comma }}"{{ scheduler }}"
{%- endfor -%} ]
num_schedulers = {{ nomad_num_schedulers }}

node_gc_threshold = "{{ nomad_node_gc_threshold }}"
eval_gc_threshold = "{{ nomad_eval_gc_threshold }}"
job_gc_threshold = "{{ nomad_job_gc_threshold }}"

encrypt = "{{ nomad_encrypt }}"
}
# Increase log verbosity
log_level = "{{nomad_log_level}}"
4 changes: 4 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Pure internal helper variables

_nomad_node_client: "{{ (nomad_node_role == 'client') or (nomad_node_role == 'both') }}"
_nomad_node_server: "{{ (nomad_node_role == 'server') or (nomad_node_role == 'both') }}"

0 comments on commit 8828144

Please sign in to comment.