@@ -28,7 +28,55 @@ promtail_data_dirs:
2828 - group: 0
2929 - makedirs: True
3030
31- {% if pillar[" promtail" ][" scrape_configs" ] is defined % }
31+ {# ================================================================
32+ NEW PATH : config_global_part + config_scrape_parts (dict )
33+ - config_global_part: string — top of promtail.yaml (server, clients, limits…)
34+ - config_scrape_parts: dict — each key is a unique name, value is a YAML
35+ string with one or more `- job_name: …` blocks.
36+ Salt deep- merges dicts, so multiple pillar SLS files each add their
37+ own key and they all end up here.
38+ If config_scrape_parts is empty or absent, a warning is issued and Promtail will not be deployed.
39+ ================================================================ # }
40+ {% set config_deployed = { ' is_ready' : false } % }
41+ {% if " config_global_part" in pillar[" promtail" ] % }
42+ {% set scrape_fragments = [] % }
43+ {% if " config_scrape_parts" in pillar[" promtail" ] % }
44+ {% for part_name in pillar[" promtail" ][" config_scrape_parts" ].keys() | sort % }
45+ {% set _ = scrape_fragments.append(pillar[" promtail" ][" config_scrape_parts" ][part_name]) % }
46+ {% endfor % }
47+ {% endif % }
48+ {% if scrape_fragments | length == 0 % }
49+
50+ promtail_no_scrape_jobs:
51+ test.configurable_test_state:
52+ - name: no_scrape_jobs_attached
53+ - changes: False
54+ - result: True
55+ - warnings: |
56+ promtail: config_global_part is set but no config_scrape_parts jobs are attached.
57+ Promtail config will NOT be deployed until at least one job pillar is connected via top_sls.
58+
59+ {% else % }
60+ {% set merged_scrape_text = scrape_fragments | join(' \n ' ) % }
61+ {% set _ = config_deployed.update({' is_ready' : true}) % }
62+
63+ promtail_config:
64+ file .managed:
65+ - name: / opt/ promtail/ etc/ promtail.yaml
66+ - mode: 644
67+ - user: 0
68+ - group: 0
69+ - contents: |
70+ {{ pillar[' promtail' ][' config_global_part' ] | indent(8 ) }}
71+ scrape_configs:
72+ {{ merged_scrape_text | indent(8 ) }}
73+ {% endif % }
74+
75+ {# ================================================================
76+ LEGACY PATH 1 : promtail.scrape_configs (uses config.jinja template)
77+ ================================================================ # }
78+ {% elif pillar[" promtail" ][" scrape_configs" ] is defined % }
79+ {% set _ = config_deployed.update({' is_ready' : true}) % }
3280promtail_config:
3381 file .managed:
3482 - name: / opt/ promtail/ etc/ promtail.yaml
@@ -44,7 +92,12 @@ promtail_config:
4492 - labels:
4593 job: varlogs
4694 __path__ : / var/ log/* log
95+
96+ {# ================================================================
97+ LEGACY PATH 2 : promtail.config (full config verbatim)
98+ ================================================================ # }
4799 {% elif pillar[" promtail" ][" config" ] is defined % }
100+ {% set _ = config_deployed.update({' is_ready' : true}) % }
48101 {% if pillar[" promtail" ][" loki" ] is defined or pillar[" promtail" ][" positions" ] is defined % }
49102when pillar contain " pillar.config" block:
50103 test.configurable_test_state:
@@ -54,18 +107,6 @@ when pillar contain "pillar.config" block:
54107 - warnings: |
55108 When pillar contain " promtail.config" block, the " promtail.positions" , " promtail.loki" blocks are IGNORED
56109 {% endif % }
57- {#
58- promtail_config:
59- file .serialize:
60- - name: / opt/ promtail/ etc/ promtail.yaml
61- - user: 0
62- - group: 0
63- - mode: 644
64- - serializer: yaml
65- - dataset_pillar: promtail:config
66- - serializer_opts:
67- - sort_keys: False
68- # }
69110promtail_config:
70111 file .managed:
71112 - name: / opt/ promtail/ etc/ promtail.yaml
@@ -76,7 +117,7 @@ promtail_config:
76117 {{ pillar[' promtail' ][' config' ] | indent(8 ) }}
77118 {% endif % }
78119
79- {% if ' docker' in pillar[' promtail' ] % }
120+ {% if config_deployed[ ' is_ready ' ] and ' docker' in pillar[' promtail' ] % }
80121promtail_image:
81122 cmd.run:
82123 - name: docker pull {{ pillar[' promtail' ][' docker' ][' image' ] }}
@@ -98,7 +139,7 @@ promtail_container:
98139 - watch:
99140 - / opt/ promtail/ etc/ promtail.yaml
100141 - command: - config.file=/ etc/ promtail/ promtail.yaml
101- {% else % }
142+ {% elif config_deployed[ ' is_ready ' ] % }
102143
103144promtail_binary_1:
104145 archive.extracted:
@@ -153,3 +194,4 @@ promtail_systemd_4:
153194 {% endif % }
154195 {% endif % }
155196{% endif % }
197+
0 commit comments