Skip to content

Commit

Permalink
✨ Add support for nomad's client template config (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
fairglen committed Jan 11, 2024
1 parent 48cd7a3 commit 09a6b6a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,23 @@ nomad_host_networks:
- Install Docker subsystem on nodes?
- Default value: **false**

### `nomad_template_config`
- Allow you configure client's [template config](https://developer.hashicorp.com/nomad/docs/configuration/client#template-parameters).
- Default: {}

Example:

```yaml
nomad_template_config:
vault_retry:
attempts: 12
backoff: "750ms"
max_backoff: "2m"
wait:
min: "10s"
max: "4m"
```

### `nomad_plugins`
- Allow you configure nomad plugins.
- Default: {}
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ nomad_meta: {}
nomad_bootstrap_expect: "{{ nomad_servers | count or 3 }}"
nomad_chroot_env: false
nomad_plugins: {}
nomad_template_config: {}

### Addresses
nomad_bind_address: "{{ hostvars[inventory_hostname]['ansible_'+ nomad_iface ]['ipv4']['address'] }}"
Expand Down
20 changes: 20 additions & 0 deletions templates/client.hcl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ client {
{% endfor -%}
}
{% endif %}

{% macro template_config(config, count=1, width=4) %}
{% set next_count = count + 1 %}
{% for key, value in config.items() %}
{% if value is mapping %}
{{ key | indent(count*width, first=True) }} {
{{ template_config(value, count=next_count, width=width) }}
{{ '}' | indent(count*width, first=True) }}
{% else %}
{{ key | indent(count*width, first=True) }} = {% if value is string %}"{{ value }}"{% else %}{{ value | string | lower }}{% endif %}

{% endif %}
{% endfor %}
{% endmacro %}

{% if nomad_template_config|length >0 %}
template {
{{ template_config(nomad_template_config) | replace('\'', '\"') }}
}
{% endif %}
}

{% macro plugin_config(config, count=1, width=4) %}
Expand Down

0 comments on commit 09a6b6a

Please sign in to comment.