{% set roles = grains['roles'] or [] %}
{
  "client": {
    "name": "{{grains['fqdn']}}",
    "address": "{{grains['fqdn_ip4']}}",
    "metric_prefix": "{{ grains['fqdn'].split('.')|reverse| join('.') }}",
    "subscriptions": {{(roles|list + ['all']|list) |json}}
  }
}

{% if 'roles' in grains -%}
{%   set roles = grains['roles'] -%}
{% else -%}
{%   set roles = [] -%}
{% endif -%}
{
  "client": {
    "name": "{{grains['fqdn']}}",
    "address": "{{grains['fqdn_ip4']}}",
    "metric_prefix": "{{ grains['fqdn'].split('.')|reverse| join('.') }}",
    "subscriptions": {{(roles|list + ['all']|list) |json}}
  }
}

Fix corner case where no roles are defined.
Fix corner case where no roles are defined.
