mirror of
https://github.com/saltstack-formulas/salt-formula.git
synced 2024-11-30 23:55:23 +01:00
f46b4f29d8
This state downloads formulas from git repositories and ensures that they are recorded in the file_roots setting.
53 lines
1.4 KiB
Django/Jinja
53 lines
1.4 KiB
Django/Jinja
{% set defaults = {
|
|
'baseurl': 'https://github.com/saltstack-formulas',
|
|
'basedir': '/srv/formulas',
|
|
'update': False,
|
|
'options': {},
|
|
}
|
|
%}
|
|
{% set formulas = salt['pillar.get']('salt_formulas:list', {}) %}
|
|
|
|
{%- macro formulas_git_opt(env, opt) -%}
|
|
{%- set value = salt['pillar.get']('salt_formulas:git_opts:{}:{}'.format(env, opt),
|
|
salt['pillar.get']('salt_formulas:git_opts:default:{}'.format(opt),
|
|
defaults[opt])) -%}
|
|
{%- if value is mapping -%}
|
|
{{ value|yaml }}
|
|
{%- else -%}
|
|
{{ value }}
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro formulas_roots(env) -%}
|
|
{%- set value = [] -%}
|
|
{%- for dir in formulas.get(env, []) -%}
|
|
{%- do value.append('{}/{}'.format(formulas_git_opt(env, 'basedir'), dir)) -%}
|
|
{%- endfor -%}
|
|
{{ value|yaml }}
|
|
{%- endmacro -%}
|
|
|
|
{# Generate file_roots config merging standard salt config and list of
|
|
enabled formulas #}
|
|
{%- macro file_roots(input) -%}
|
|
{%- set processed_envs = [] -%}
|
|
file_roots:
|
|
{%- for name, roots in input|dictsort -%}
|
|
{%- do processed_envs.append(name) %}
|
|
{{ name }}:
|
|
{%- for dir in roots %}
|
|
- {{ dir }}
|
|
{%- endfor -%}
|
|
{%- for dir in formulas_roots(name)|load_yaml %}
|
|
- {{ dir }}
|
|
{%- endfor -%}
|
|
{%- endfor -%}
|
|
{%- for name in formulas -%}
|
|
{%- if name not in processed_envs %}
|
|
{{ name }}:
|
|
{%- for dir in formulas_roots(name)|load_yaml %}
|
|
- {{ dir }}
|
|
{%- endfor -%}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- endmacro -%}
|