Refactor Matterbridge profile #11

Merged
pratyush merged 1 commits from matterbridge-refactor into production 2023-02-09 20:44:04 +01:00
2 changed files with 26 additions and 23 deletions

View File

@ -1,35 +1,33 @@
{%- set header = salt['pillar.get']('managed_header_pound') -%} {%- set header = salt['pillar.get']('managed_header_pound') -%}
{%- set myfqdn = salt['grains.get']('fqdn') -%}
{%- set mypillar = 'profile:matterbridge:instances:' ~ instance ~ ':' -%}
{%- set myaccounts = mypillar ~ 'accounts' -%}
{%- set mygateways = mypillar ~ 'gateways' -%}
{%- set generalopts = ['RemoteNickFormat', 'IgnoreFailureOnStart', 'MessageSplit', 'MediaDownloadSize', 'MediaDownloadPath', 'MediaServerDownload', 'LogFile'] -%}
{%- set accountopts = ['Nick', 'NickServNick', 'NickServPassword', 'Server', 'UseTLS', 'UseSASL', 'Label', 'Charset', 'IgnoreNicks', 'RunCommands', 'UseRelayMsg', 'RemoteNickFormat'] -%}
{{ header }} {{ header }}
{%- if general | length %}
[general] [general]
{% for option in generalopts %} {%- for option, value in general.items() %}
{%- if salt['pillar.get'](mypillar ~ option, None) != None %} {%- if value is string %}
{{ option }}="{{ salt['pillar.get'](mypillar ~ option) }}" {%- set value = '"' ~ value ~ '"' %}
{%- endif -%} {%- endif %}
{%- endfor -%} {{ option }}={{ value }}
{%- endfor %}
{% endif %}
{% for account, config in salt['pillar.get'](myaccounts).items() %} {%- for account, config in accounts.items() %}
[{{ config['protocol'] }}.{{ account }}] [{{ account }}]
{%- for option in accountopts %} {%- for option, value in config.items() %}
{%- if salt['pillar.get'](myaccounts ~ ':' ~ account ~ ':' ~ option, None) != None %} {%- if value is string %}
{{ option }}="{{ config[option] }}" {%- set value = '"' ~ value ~ '"' %}
{%- endif -%} {%- endif %}
{{ option }}={{ value }}
{%- endfor %}
{% endfor %} {% endfor %}
{% endfor -%}
{% for gateway, config in salt['pillar.get'](mygateways).items() %} {%- for gateway, config in gateways.items() %}
[[gateway]] [[gateway]]
name="{{ gateway }}" name="{{ gateway }}"
enable=true enable=true
{% for account, channel in config.items() %} {%- for account, channel in config.items() %}
[[gateway.inout]] [[gateway.inout]]
account="{{ account }}" account="{{ account }}"
channel="{{ channel }}" channel="{{ channel }}"
{%- endfor %}
{% endfor %} {% endfor %}
{%- endfor -%}

View File

@ -1,5 +1,5 @@
{%- set mypillar = 'profile:matterbridge' -%} {%- set mypillar = salt['pillar.get']('profile:matterbridge') -%}
{%- set instances = salt['pillar.get'](mypillar ~ ':instances') or [] -%} {%- set instances = mypillar['instances'] | default([]) -%}
matterbridge_packages: matterbridge_packages:
pkg.installed: pkg.installed:
@ -31,7 +31,12 @@ matterbridge_files:
- /etc/matterbridge/{{ instance }}.toml: - /etc/matterbridge/{{ instance }}.toml:
- context: - context:
instance: {{ instance }} instance: {{ instance }}
general: {{ instances[instance]['general'] | default({}) }}
accounts: {{ instances[instance]['accounts'] }}
gateways: {{ instances[instance]['gateways'] }}
{%- endfor %}
{%- for instance in instances %}
matterbridge_{{ instance }}_service: matterbridge_{{ instance }}_service:
service.running: service.running:
- name: matterbridge@{{ instance }}.service - name: matterbridge@{{ instance }}.service