Pārlūkot izejas kodu

Extract jinja macro

master
Nicolas Rodriguez pirms 7 gadiem
vecāks
revīzija
1820744c38
2 mainītis faili ar 28 papildinājumiem un 25 dzēšanām
  1. +1
    -25
      syslog_ng/files/syslog-ng.conf
  2. +27
    -0
      syslog_ng/macro.jinja

+ 1
- 25
syslog_ng/files/syslog-ng.conf Parādīt failu

@@ -1,30 +1,6 @@
{%- from "syslog_ng/macro.jinja" import rule_builder -%}
{%- set syslog_config = pillar.get('syslog_ng', {}) -%}

{%- macro rule_builder(rule) -%}
{%- if rule is none -%}
{%- elif rule is sameas true -%}
yes
{%- elif rule is sameas false -%}
no
{%- elif rule is number -%}
{{ rule }}
{%- elif rule is mapping -%}
{%- for k, v in rule.items() -%}
{{ k }}({{ rule_builder(v) }})
{%- endfor -%}
{%- elif rule is iterable and rule is not string -%}
{%- for v in rule -%}
{{ rule_builder(v) }}
{%- endfor -%}
{%- else -%}
{%- if rule[0] == '=' -%}
{{ rule[1:] }}
{%- else -%}
"{{ rule }}"
{%- endif -%}
{%- endif -%}
{%- endmacro -%}

@version: {{ syslog_config.get('version', '3.3') }}

{%- for module in syslog_config.get('module', []) %}

+ 27
- 0
syslog_ng/macro.jinja Parādīt failu

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# vim: ft=jinja

{%- macro rule_builder(rule) -%}
{%- if rule is none -%}
{%- elif rule is sameas true -%}
yes
{%- elif rule is sameas false -%}
no
{%- elif rule is number -%}
{{ rule }}
{%- elif rule is mapping -%}
{%- for k, v in rule.items() -%}
{{ k }}({{ rule_builder(v) }})
{%- endfor -%}
{%- elif rule is iterable and rule is not string -%}
{%- for v in rule -%}
{{ rule_builder(v) }}
{%- endfor -%}
{%- else -%}
{%- if rule[0] == '=' -%}
{{ rule[1:] }}
{%- else -%}
"{{ rule }}"
{%- endif -%}
{%- endif -%}
{%- endmacro -%}

Notiek ielāde…
Atcelt
Saglabāt