|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- {%- 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 }}
- - 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
- - 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
- - makedirs: True
-
- {%- endif %}
-
- {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
-
- {%- if formula.source == 'pkg' %}
-
- salt_master_{{ environment_name }}_{{ formula.name }}_formula:
- pkg.latest:
- - name: {{ formula.name }}
-
- {%- elif 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 %}
- - 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
-
- {%- 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 }}
-
- {%- 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 }}
-
- {%- 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 }}
-
- {%- 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
-
- {%- 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 }}
-
- {%- 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 }}
-
- {%- 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 }}
-
- {%- endfor %}
-
- {%- endif %}
-
- {%- endif %}
-
- {%- endfor %}
-
- {%- endfor %}
-
- {# end new #}
-
- {%- endif %}
-
|