|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- {%- from "salt/map.jinja" import master with context %}
- {%- if master.enabled %}
-
- include:
- - git.client
- - salt.master.service
-
- {%- if master.system is defined %}
-
- salt_env_{{ master.system.environment }}_dirs_obsolete:
- file.directory:
- - names:
- - /srv/salt/env/{{ master.system.environment }}/_modules
- - /srv/salt/env/{{ master.system.environment }}/_states
- - /srv/salt/env/{{ master.system.environment }}/_grains
- - /srv/salt/env/{{ master.system.environment }}/_engines
- - /srv/salt/env/{{ master.system.environment }}
- - makedirs: True
-
- {%- for grain_name, grain in master.system.get('grain', {}).iteritems() %}
-
- {%- if grain.source == 'git' %}
-
- salt_master_{{ master.system.environment }}_{{ grain_name }}_grain_source:
- git.latest:
- - name: {{ grain.address }}
- - target: /srv/salt/env/{{ master.system.environment }}/_extra/grain_{{ grain_name }}
- - rev: {{ grain.revision }}
- - require:
- - file: salt_env_{{ master.system.environment }}_dirs
- - pkg: git_packages
-
- /srv/salt/env/{{ master.system.environment }}/_grains/{{ grain_name }}.py:
- file.symlink:
- - target: /srv/salt/env/{{ master.system.environment }}/_extra/grain_{{ grain_name }}/{{ grain_name }}.py
- - require:
- - git: salt_master_{{ master.system.environment }}_{{ grain_name }}_grain_source
-
- {%- endif %}
-
- {%- endfor %}
-
- {%- for state_name, state in master.system.get('state', {}).iteritems() %}
-
- {%- if state.source == 'git' %}
-
- salt_master_{{ master.system.environment }}_{{ state_name }}_state_source:
- git.latest:
- - name: {{ state.address }}
- - target: /srv/salt/env/{{ master.system.environment }}/_extra/state_{{ state_name }}
- - rev: {{ state.revision }}
- - require:
- - file: salt_env_{{ master.system.environment }}_dirs
- - pkg: git_packages
-
- /srv/salt/env/{{ master.system.environment }}/_modules/{{ state_name }}.py:
- file.symlink:
- - target: /srv/salt/env/{{ master.system.environment }}/_extra/state_{{ state_name }}/modules/{{ state_name }}.py
- - require:
- - git: salt_master_{{ master.system.environment }}_{{ state_name }}_state_source
-
- /srv/salt/env/{{ master.system.environment }}/_states/{{ state_name }}.py:
- file.symlink:
- - target: /srv/salt/env/{{ master.system.environment }}/_extra/state_{{ state_name }}/states/{{ state_name }}.py
- - require:
- - git: salt_master_{{ master.system.environment }}_{{ state_name }}_state_source
-
- {%- endif %}
-
- {%- endfor %}
-
- {%- for formula_name, formula in master.system.get('formula', {}).iteritems() %}
-
- {%- if formula.source == 'git' %}
-
- salt_master_{{ master.system.environment }}_{{ formula_name }}_formula_source:
- git.latest:
- - name: {{ formula.address }}
- - target: /srv/salt/env/{{ master.system.environment }}/{{ formula_name }}
- - rev: {{ formula.revision }}
- - require:
- - file: salt_env_{{ master.system.environment }}_dirs
- - pkg: git_packages
-
- {%- endif %}
-
- {%- endfor %}
-
- {%- if master.system.returners is defined %}
-
- salt_master_{{ master.system.environment }}_returners:
- git.latest:
- - name: {{ master.system.returners.address }}
- - target: /srv/salt/env/{{ master.system.environment }}/_returners
- - rev: {{ master.system.returners.revision }}
- - require:
- - file: salt_env_{{ master.system.environment }}_dirs
- - pkg: git_packages
-
- {%- endif %}
-
- {%- endif %}
-
- {# Start new #}
-
- {%- for environment_name, environment in master.get('environment', {}).iteritems() %}
-
- {%- if master.base_environment == environment_name %}
-
- salt_env_{{ environment_name }}_pre_dirs:
- file.directory:
- - names:
- - /usr/share/salt-formulas/env/_modules
- - /usr/share/salt-formulas/env/_states
- - /usr/share/salt-formulas/env/_grains
- - /usr/share/salt-formulas/env/_formulas
- - /usr/share/salt-formulas/env/_engines
- - /usr/share/salt-formulas/env/_runners
- - makedirs: True
-
- salt_env_{{ environment_name }}_dirs:
- file.symlink:
- - name: /srv/salt/env/{{ environment_name }}
- - target: /usr/share/salt-formulas/env
- - require:
- - file: salt_env_{{ environment_name }}_pre_dirs
-
- {%- else %}
-
- salt_env_{{ environment_name }}_dirs:
- file.directory:
- - names:
- - /srv/salt/env/{{ environment_name }}/_modules
- - /srv/salt/env/{{ environment_name }}/_states
- - /srv/salt/env/{{ environment_name }}/_grains
- - /srv/salt/env/{{ environment_name }}/_formulas
- - /srv/salt/env/{{ environment_name }}/_engines
- - /srv/salt/env/{{ environment_name }}/_runners
- - makedirs: True
-
- {%- endif %}
-
- {%- set _formula_pkgs = [] %}
- {%- set _formula_pkgs_with_version = [] %}
- {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
- {%- if formula.source == 'pkg' %}
- {%- if formula.version is defined %}
- {%- do _formula_pkgs_with_version.append(formula) %}
- {%- else %}
- {%- do _formula_pkgs.append(formula.name) %}
- {%- endif %}
- {%- endif %}
- {%- endfor %}
-
- {% if _formula_pkgs|length > 1 %}
- salt_master_{{ environment_name }}_pkg_formulas:
- pkg.latest:
- - pkgs:
- {%- for pkg in _formula_pkgs %}
- - {{ pkg }}
- {%- endfor %}
- - refresh: True
- - cache_valid_time: 300
- {% endif %}
-
- {% if _formula_pkgs_with_version|length > 1 %}
- {%- for formula in _formula_pkgs_with_version %}
- salt_master_{{ environment_name }}_pkg_formula_{{ formula.name }}:
- {%- if formula.version == 'latest' %}
- pkg.latest:
- - refresh: True
- - cache_valid_time: 300
- {%- elif formula.version == 'purged' %}
- pkg.purged:
- {%- elif formula.version == 'removed' %}
- pkg.removed:
- {%- else %}
- pkg.installed:
- - version: {{ formula.version }}
- - refresh: True
- - cache_valid_time: 300
- {% endif %}
- - name: {{ formula.name }}
- {%- endfor %}
-
- {% endif %}
-
- {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
-
- {%- if formula.source == 'git' %}
-
- {%- if master.base_environment == environment_name %}
-
- salt_master_{{ environment_name }}_{{ formula_name }}_formula:
- git.latest:
- - name: {{ formula.address }}
- - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
- {% if formula.get("revision", "").split("/")[0] == "refs" %}
- - rev: {{ formula.branch|default("master") }}
- {%- if grains['saltversion'] >= "2015.8.0" %}
- - branch: {{ formula.branch|default("master") }}
- {%- endif %}
- {% else %}
- - rev: {{ formula.revision|default(formula.branch) }}
- {%- if grains['saltversion'] >= "2015.8.0" %}
- - branch: {{ formula.branch|default(formula.revision) }}
- {%- endif %}
- {% endif %}
- - submodules: {{ formula.submodules|default(False) }}
- - force_reset: {{ formula.force_reset|default(False) }}
- - require:
- - file: salt_env_{{ environment_name }}_dirs
- - pkg: git_packages
-
- {%- if formula.get("revision", "").split("/")[0] == "refs" %}
-
- salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch:
- module.run:
- - name: git.fetch
- - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
- - opts: {{ formula.address }} {{ formula.revision }}
- - require:
- - git: salt_master_{{ environment_name }}_{{ formula_name }}_formula
-
- salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset:
- module.run:
- - name: git.reset
- - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
- - opts: --hard FETCH_HEAD
- - require:
- - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch
-
- salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_rebase:
- module.run:
- - name: git.rebase
- - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
- - rev: origin/{{ formula.branch|default("master") }}
- - require:
- - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset
-
- {%- endif %}
-
- salt_env_{{ environment_name }}_{{ formula_name }}_link:
- file.symlink:
- - name: /usr/share/salt-formulas/env/{{ formula_name }}
- - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/{{ formula_name }}
- - require:
- - file: salt_env_{{ environment_name }}_dirs
- - force: True
- - makedirs: True
-
- {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
-
- salt_master_{{ environment_name }}_{{ grain_name }}_grain:
- file.symlink:
- - name: /usr/share/salt-formulas/env/_grains/{{ grain_name }}
- - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
- - force: True
- - makedirs: True
-
- {%- endfor %}
-
- {%- for module_name, module in formula.get('module', {}).iteritems() %}
-
- salt_master_{{ environment_name }}_{{ module_name }}_module:
- file.symlink:
- - name: /usr/share/salt-formulas/env/_modules/{{ module_name }}
- - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_modules/{{ module_name }}
- - force: True
- - makedirs: True
-
- {%- endfor %}
-
- {%- for state_name, state in formula.get('state', {}).iteritems() %}
-
- salt_master_{{ environment_name }}_{{ state_name }}_state:
- file.symlink:
- - name: /usr/share/salt-formulas/env/_states/{{ state_name }}
- - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_states/{{ state_name }}
- - force: True
- - makedirs: True
-
- {%- endfor %}
-
- {%- else %}
-
- salt_master_{{ environment_name }}_{{ formula_name }}_formula:
- git.latest:
- - name: {{ formula.address }}
- - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}
- - rev: {{ formula.revision }}
- - require:
- - file: salt_env_{{ environment_name }}_dirs
- - pkg: git_packages
-
- salt_env_{{ environment_name }}_{{ formula_name }}_link:
- file.symlink:
- - name: /srv/salt/env/{{ environment_name }}/{{ formula_name }}
- - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/{{ formula_name }}
- - require:
- - file: salt_env_{{ environment_name }}_dirs
- - force: True
- - makedirs: True
-
- {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
-
- salt_master_{{ environment_name }}_{{ grain_name }}_grain:
- file.symlink:
- - name: /srv/salt/env/{{ environment_name }}/_grains/{{ grain_name }}
- - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
- - force: True
- - makedirs: True
-
- {%- endfor %}
-
- {%- for module_name, module in formula.get('module', {}).iteritems() %}
-
- salt_master_{{ environment_name }}_{{ module_name }}_module:
- file.symlink:
- - name: /srv/salt/env/{{ environment_name }}/_grains/{{ module_name }}
- - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ module_name }}
- - force: True
- - makedirs: True
-
- {%- endfor %}
-
- {%- for state_name, state in formula.get('state', {}).iteritems() %}
-
- salt_master_{{ environment_name }}_{{ state_name }}_state:
- file.symlink:
- - name: /srv/salt/env/{{ environment_name }}/_grains/{{ state_name }}
- - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ state_name }}
- - force: True
- - makedirs: True
-
- {%- endfor %}
-
- {%- for engine_name, engine in formula.get('engine', {}).iteritems() %}
-
- salt_master_{{ environment_name }}_{{ engine_name }}_engine:
- file.symlink:
- - name: /srv/salt/env/{{ environment_name }}/_engines/{{ engine_name }}
- - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_engines/{{ engine_name }}
- - force: True
- - makedirs: True
-
- {%- endfor %}
-
- {%- for runner_name, runner in formula.get('runner', {}).iteritems() %}
-
- salt_master_{{ environment_name }}_{{ runner_name }}_runner:
- file.symlink:
- - name: /srv/salt/env/{{ environment_name }}/_engines/{{ runner_name }}
- - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_engines/{{ runner_name }}
- - force: True
- - makedirs: True
-
- {%- endfor %}
-
- {%- endif %}
-
- {%- endif %}
-
- {%- endfor %}
-
- {%- endfor %}
-
- {# end new #}
-
- {%- endif %}
-
|