{%- from "linux/map.jinja" import system,network with context -%}
orchestrate:
  system:
    priority: 30
  network:
    priority: 40
  storage:
    priority: 50
grain:
  sphinx:
    {%- set service_grains = {'sphinx': {'doc': {}}} %}
    {%- for service_name, service in pillar.items() %}
      {%- if service.get('_support', {}).get('sphinx', {}).get('enabled', False) %}
        {%- set grains_fragment_file = service_name+'/meta/sphinx.yml' %}
        {%- macro load_grains_file() %}{% include grains_fragment_file ignore missing %}{% endmacro %}
        {%- set grains = load_grains_file()|load_yaml %}
        {%- if grains %}
          {%- set grains_yaml = load_grains_file()|load_yaml %}
          {%- do service_grains.sphinx.doc.update({ service_name: grains_yaml.doc }) %}
        {%- endif %}
      {%- endif %}
    {%- endfor %}
    {{ service_grains|yaml(False)|indent(4) }}
  {%- set dns_records = [] %}
  {%- for host_name, host in network.host.items() %}
  {%- if host.get('grain', False) %}
  {%- do host.pop('grain') %}
  {%- do dns_records.append(host) %}
  {%- endif %}
  {%- endfor %}
  dns_records: 
    dns_records: {{ dns_records|yaml }}