mirror of
https://github.com/saltstack-formulas/salt-formula.git
synced 2026-10-24 05:39:08 +02:00
Add new “salt.formulas” state to manage salt formulas
This state downloads formulas from git repositories and ensures that they are recorded in the file_roots setting.
This commit is contained in:
1 parent
02f8debea8
commit
f46b4f29d8
6 files changed
+181
-32
No files matched your search
@@ -12,6 +12,7 @@
|
||||
#{{ configname }}: {{ default_value }}
|
||||
{%- endif -%}
|
||||
{%- endmacro -%}
|
||||
{%- from 'salt/formulas.jinja' import file_roots, formulas -%}
|
||||
##### Primary configuration settings #####
|
||||
##########################################
|
||||
# This configuration file is used to manage the behavior of the Salt Master
|
||||
@@ -473,22 +474,12 @@ client_acl_blacklist:
|
||||
# - /srv/salt/prod/states
|
||||
|
||||
{% if 'file_roots' in master -%}
|
||||
file_roots:
|
||||
{%- for name, roots in master['file_roots']|dictsort %}
|
||||
{{ name }}:
|
||||
{%- for dir in roots %}
|
||||
- {{ dir }}
|
||||
{%- endfor -%}
|
||||
{%- endfor -%}
|
||||
{% elif 'file_roots' in salt -%}
|
||||
file_roots:
|
||||
{%- for name, roots in salt['file_roots']|dictsort %}
|
||||
{{ name }}:
|
||||
{%- for dir in roots %}
|
||||
- {{ dir }}
|
||||
{%- endfor -%}
|
||||
{%- endfor -%}
|
||||
{% else -%}
|
||||
{{ file_roots(master['file_roots']) }}
|
||||
{%- elif 'file_roots' in salt -%}
|
||||
{{ file_roots(salt['file_roots']) }}
|
||||
{%- elif formulas|length -%}
|
||||
{{ file_roots({'base': ['/srv/salt']}) }}
|
||||
{%- else -%}
|
||||
#file_roots:
|
||||
# base:
|
||||
# - /srv/salt
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#{{ configname }}: {{ default_value }}
|
||||
{%- endif -%}
|
||||
{%- endmacro -%}
|
||||
{%- from 'salt/formulas.jinja' import file_roots, formulas -%}
|
||||
##### Primary configuration settings #####
|
||||
##########################################
|
||||
|
||||
@@ -408,22 +409,12 @@ file_client: local
|
||||
# - /srv/salt/prod/states
|
||||
#
|
||||
{% if 'file_roots' in minion -%}
|
||||
file_roots:
|
||||
{%- for name, roots in minion['file_roots']|dictsort %}
|
||||
{{ name }}:
|
||||
{%- for dir in roots %}
|
||||
- {{ dir }}
|
||||
{%- endfor -%}
|
||||
{%- endfor -%}
|
||||
{% elif 'file_roots' in salt -%}
|
||||
file_roots:
|
||||
{%- for name, roots in salt['file_roots']|dictsort %}
|
||||
{{ name }}:
|
||||
{%- for dir in roots %}
|
||||
- {{ dir }}
|
||||
{%- endfor -%}
|
||||
{%- endfor -%}
|
||||
{% else -%}
|
||||
{{ file_roots(minion['file_roots']) }}
|
||||
{%- elif 'file_roots' in salt -%}
|
||||
{{ file_roots(salt['file_roots']) }}
|
||||
{%- elif formulas|length -%}
|
||||
{{ file_roots({'base': ['/srv/salt']}) }}
|
||||
{%- else -%}
|
||||
#file_roots:
|
||||
# base:
|
||||
# - /srv/salt
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
{% 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 -%}
|
||||
@@ -0,0 +1,44 @@
|
||||
{% set processed_gitdirs = [] %}
|
||||
{% set processed_basedirs = [] %}
|
||||
|
||||
{% from "salt/formulas.jinja" import formulas_git_opt with context %}
|
||||
|
||||
# Loop over all formulas listed in pillar data
|
||||
{% for env, entries in salt['pillar.get']('salt_formulas:list').iteritems() %}
|
||||
{% for entry in entries %}
|
||||
|
||||
{% set basedir = formulas_git_opt(env, 'basedir') %}
|
||||
{% set gitdir = '{}/{}'.format(basedir, entry) %}
|
||||
{% set update = formulas_git_opt(env, 'update')|load_yaml %}
|
||||
|
||||
# Setup the directory hosting the Git repository
|
||||
{% if basedir not in processed_basedirs %}
|
||||
{% do processed_basedirs.append(basedir) %}
|
||||
{{ basedir }}:
|
||||
file.directory:
|
||||
{%- for key, value in salt['pillar.get']('salt_formulas:basedir_opts',
|
||||
{'makedirs': True}).iteritems() %}
|
||||
- {{ key }}: {{ value }}
|
||||
{%- endfor %}
|
||||
{% endif %}
|
||||
|
||||
# Setup the formula Git repository
|
||||
{% if gitdir not in processed_gitdirs %}
|
||||
{% do processed_gitdirs.append(gitdir) %}
|
||||
{% set options = formulas_git_opt(env, 'options')|load_yaml %}
|
||||
{{ gitdir }}:
|
||||
git.latest:
|
||||
- name: {{ formulas_git_opt(env, 'baseurl') }}/{{ entry }}.git
|
||||
- target: {{ gitdir }}
|
||||
{%- for key, value in options.iteritems() %}
|
||||
- {{ key }}: {{ value }}
|
||||
{%- endfor %}
|
||||
- require:
|
||||
- file: {{ basedir }}
|
||||
{%- if not update %}
|
||||
- unless: test -e {{ gitdir }}
|
||||
{%- endif %}
|
||||
{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
Reference in new issue
Block a user