Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support for nomad's client template config #175

Merged
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 @@ -30,13 +30,13 @@
nomad_debug: false

## Asserts
nomad_skip_ensure_all_hosts: "{{ lookup('env','NOMAD_SKIP_ENSURE_ALL_HOSTS') | default('false', true) }}"

Check warning on line 33 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

jinja[spacing]

Jinja2 spacing could be improved: {{ lookup('env','NOMAD_SKIP_ENSURE_ALL_HOSTS') | default('false', true) }} -> {{ lookup('env', 'NOMAD_SKIP_ENSURE_ALL_HOSTS') | default('false', true) }}

## Config Purge
nomad_allow_purge_config: "{{ lookup('env','NOMAD_ALLOW_PURGE_CONFIG') | default('false', true) }}"

Check warning on line 36 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

jinja[spacing]

Jinja2 spacing could be improved: {{ lookup('env','NOMAD_ALLOW_PURGE_CONFIG') | default('false', true) }} -> {{ lookup('env', 'NOMAD_ALLOW_PURGE_CONFIG') | default('false', true) }}

### Package
nomad_version: "{{ lookup('env','NOMAD_VERSION') | default('1.1.1', true) }}"

Check warning on line 39 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

jinja[spacing]

Jinja2 spacing could be improved: {{ lookup('env','NOMAD_VERSION') | default('1.1.1', true) }} -> {{ lookup('env', 'NOMAD_VERSION') | default('1.1.1', true) }}
nomad_architecture_map:
amd64: amd64
x86_64: amd64
Expand All @@ -45,12 +45,12 @@
32-bit: "386"
64-bit: amd64
nomad_architecture: "{{ nomad_architecture_map[ansible_architecture] }}"
nomad_pkg: "nomad_{{ nomad_version }}_linux_{{nomad_architecture}}.zip"

Check warning on line 48 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

jinja[spacing]

Jinja2 spacing could be improved: nomad_{{ nomad_version }}_linux_{{nomad_architecture}}.zip -> nomad_{{ nomad_version }}_linux_{{ nomad_architecture }}.zip
nomad_zip_url: "https://releases.hashicorp.com/nomad/{{ nomad_version }}/nomad_{{ nomad_version }}_linux_{{nomad_architecture}}.zip"

Check warning on line 49 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

jinja[spacing]

Jinja2 spacing could be improved: https://releases.hashicorp.com/nomad/{{ nomad_version }}/nomad_{{ nomad_version }}_linux_{{nomad_architecture}}.zip -> https://releases.hashicorp.com/nomad/{{ nomad_version }}/nomad_{{ nomad_version }}_linux_{{ nomad_architecture }}.zip
nomad_checksum_file_url: "https://releases.hashicorp.com/nomad/{{ nomad_version }}/nomad_{{ nomad_version}}_SHA256SUMS"

Check warning on line 50 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

jinja[spacing]

Jinja2 spacing could be improved: https://releases.hashicorp.com/nomad/{{ nomad_version }}/nomad_{{ nomad_version}}_SHA256SUMS -> https://releases.hashicorp.com/nomad/{{ nomad_version }}/nomad_{{ nomad_version }}_SHA256SUMS
nomad_podman_enable: false
nomad_podman_version: "{{ lookup('env','NOMAD_PODMAN_VERSION') | default('0.3.0', true) }}"

Check warning on line 52 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

jinja[spacing]

Jinja2 spacing could be improved: {{ lookup('env','NOMAD_PODMAN_VERSION') | default('0.3.0', true) }} -> {{ lookup('env', 'NOMAD_PODMAN_VERSION') | default('0.3.0', true) }}
nomad_podman_pkg: "nomad-driver-podman_{{ nomad_podman_version }}_linux_{{nomad_architecture}}.zip"

Check warning on line 53 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

jinja[spacing]

Jinja2 spacing could be improved: nomad-driver-podman_{{ nomad_podman_version }}_linux_{{nomad_architecture}}.zip -> nomad-driver-podman_{{ nomad_podman_version }}_linux_{{ nomad_architecture }}.zip
nomad_podman_url: "https://releases.hashicorp.com/nomad-driver-podman/{{ nomad_podman_version }}"
nomad_podman_zip_url: "{{ nomad_podman_url }}/{{ nomad_podman_pkg }}"
nomad_podman_checksum_file_url: "{{ nomad_podman_url }}/nomad-driver-podman_{{ nomad_podman_version }}_SHA256SUMS"
Expand Down Expand Up @@ -78,9 +78,9 @@
nomad_region: "global"
nomad_log_level: "INFO"
nomad_syslog_enable: true
nomad_iface: "{{ lookup('env','NOMAD_IFACE') | default(ansible_default_ipv4.interface, true) }}"

Check warning on line 81 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

jinja[spacing]

Jinja2 spacing could be improved: {{ lookup('env','NOMAD_IFACE') | default(ansible_default_ipv4.interface, true) }} -> {{ 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) }}"

Check warning on line 83 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

jinja[spacing]

Jinja2 spacing could be improved: {{ lookup('env','NOMAD_NODE_ROLE') | default('client', true) }} -> {{ lookup('env', 'NOMAD_NODE_ROLE') | default('client', true) }}
nomad_leave_on_terminate: true
nomad_leave_on_interrupt: false
nomad_disable_update_check: false
Expand Down Expand Up @@ -125,6 +125,7 @@
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
Loading