|
|
@@ -1,43 +1,113 @@ |
|
|
|
{%- from "salt/map.jinja" import master with context %} |
|
|
|
{%- if master.enabled %} |
|
|
|
|
|
|
|
{{ formula_dict }} |
|
|
|
|
|
|
|
{%- for environment_name, environment in master.get('environment', {}).iteritems() %} |
|
|
|
{%- if master.enabled %} |
|
|
|
{%- for environment_name, environment in master.get('environment', {}).iteritems() %} |
|
|
|
{%- if master.base_environment == environment_name %} |
|
|
|
{%- set sorted_priorities = priorities|dictsort(false, 'value') %} |
|
|
|
{#- Set debug = True to log simple state result - Fail/True - to /var/log/salt/ on both master and respective minions #} |
|
|
|
{%- set debug = False %} |
|
|
|
{#- Uncomment to print parsed metadata from formula_name/meta/salt.yml to output file %} |
|
|
|
|
|
|
|
{%- if master.base_environment == environment_name %} |
|
|
|
PARSED METADATA: |
|
|
|
|
|
|
|
{%- set formula_dict = environment.get('formula', {}) %} |
|
|
|
{%- set new_formula_dict = {} %} |
|
|
|
--------------- |
|
|
|
|
|
|
|
{%- for formula_name, formula in formula_dict.iteritems() %} |
|
|
|
Passed from salt/master/orchestrate.sls |
|
|
|
--- |
|
|
|
|
|
|
|
{%- set _tmp = new_formula_dict.update({formula_name: formula.get('orchestrate_order', 100)}) %} |
|
|
|
priorities: {{ priorities }} |
|
|
|
|
|
|
|
{%- endfor %} |
|
|
|
sorted_priorities: {{ sorted_priorities }} |
|
|
|
|
|
|
|
{%- set sorted_formula_list = new_formula_dict|dictsort(false, 'value') %} |
|
|
|
|
|
|
|
{%- for formula in sorted_formula_list %} |
|
|
|
args: {{ args }} |
|
|
|
|
|
|
|
{%- if salt['file.file_exists']('/srv/salt/env/'+environment_name+'/'+formula.0+'/orchestrate.sls') %} |
|
|
|
--------------- |
|
|
|
|
|
|
|
{{ salt['cmd.run']('cat /srv/salt/env/'+environment_name+'/'+formula.0+'/orchestrate.sls') }} |
|
|
|
#} |
|
|
|
|
|
|
|
{%- else %} |
|
|
|
{%- for state in sorted_priorities %} |
|
|
|
{%- set formula = state.0.split('.') %} |
|
|
|
|
|
|
|
{{ formula.0 }}: |
|
|
|
salt.state: |
|
|
|
- tgt: 'services:{{ formula.0 }}' |
|
|
|
- tgt_type: grain |
|
|
|
- sls: {{ formula.0 }} |
|
|
|
{%- if salt['file.directory_exists']('/srv/salt/env/'+environment_name+'/'+formula.0+'/orchestrate') and formula|length > 1 and salt['file.file_exists']('/srv/salt/env/'+environment_name+'/'+formula.0+'/orchestrate/'+formula.1+'.sls') %} |
|
|
|
|
|
|
|
{%- endif %} |
|
|
|
{{ salt['cmd.run']('cat /srv/salt/env/'+environment_name+'/'+formula.0+'/orchestrate/'+formula.1+'.sls') }} |
|
|
|
|
|
|
|
{%- endfor %} |
|
|
|
{%- else %} |
|
|
|
{%- if args[ state.0 ] is defined %} |
|
|
|
|
|
|
|
{{ state.0 }}: |
|
|
|
salt.state: |
|
|
|
- tgt: '{{ state.0|replace(".", ":") }}' |
|
|
|
- tgt_type: pillar |
|
|
|
- queue: True |
|
|
|
- sls: {{ state.0 }} |
|
|
|
{{ args[ state.0 ]|yaml(false)|indent(4) }} |
|
|
|
|
|
|
|
{%- if debug %} |
|
|
|
|
|
|
|
{{ state.0 }}.logok: |
|
|
|
salt.function: |
|
|
|
- tgt: 'I@salt:master or I@{{ state.0|replace(".", ":") }}' |
|
|
|
- tgt_type: compound |
|
|
|
- queue: True |
|
|
|
- name: cmd.run |
|
|
|
- arg: |
|
|
|
- 'echo "$(date +"%d %h %Y %H:%M:%S") | state: {{ state.0}} - status: OK" >> /var/log/salt/orchestrate_runner' |
|
|
|
- require: |
|
|
|
- salt: {{ state.0 }} |
|
|
|
|
|
|
|
{{ state.0 }}.logfail: |
|
|
|
salt.function: |
|
|
|
- tgt: 'I@salt:master or I@{{ state.0|replace(".", ":") }}' |
|
|
|
- tgt_type: compound |
|
|
|
- queue: True |
|
|
|
- name: cmd.run |
|
|
|
- arg: |
|
|
|
- 'echo "$(date +"%d %h %Y %H:%M:%S") | state: {{ state.0}} - status: FAIL" >> /var/log/salt/orchestrate_runner' |
|
|
|
- onfail: |
|
|
|
- salt: {{ state.0 }} |
|
|
|
|
|
|
|
{%- endif %} |
|
|
|
{%- else %} |
|
|
|
|
|
|
|
{{ state.0 }}: |
|
|
|
salt.state: |
|
|
|
- tgt: '{{ state.0|replace(".", ":") }}{%- if "." not in state.0 %}:*{%- endif %}' |
|
|
|
- tgt_type: pillar |
|
|
|
- queue: True |
|
|
|
- sls: {{ state.0 }} |
|
|
|
|
|
|
|
{%- if debug %} |
|
|
|
|
|
|
|
{{ state.0 }}.logok: |
|
|
|
salt.function: |
|
|
|
- tgt: 'I@salt:master or I@{{ state.0|replace(".", ":") }}' |
|
|
|
- tgt_type: compound |
|
|
|
- queue: True |
|
|
|
- name: cmd.run |
|
|
|
- arg: |
|
|
|
- 'echo "$(date +"%d %h %Y %H:%M:%S") | state: {{ state.0}} - status: OK" >> /var/log/salt/orchestrate_runner' |
|
|
|
- require: |
|
|
|
- salt: {{ state.0 }} |
|
|
|
|
|
|
|
{{ state.0 }}.logfail: |
|
|
|
salt.function: |
|
|
|
- tgt: 'I@salt:master or I@{{ state.0|replace(".", ":") }}' |
|
|
|
- tgt_type: compound |
|
|
|
- queue: True |
|
|
|
- name: cmd.run |
|
|
|
- arg: |
|
|
|
- 'echo "$(date +"%d %h %Y %H:%M:%S") | state: {{ state.0}} - status: FAIL" >> /var/log/salt/orchestrate_runner' |
|
|
|
- onfail: |
|
|
|
- salt: {{ state.0 }} |
|
|
|
|
|
|
|
{%- endif %} |
|
|
|
{%- endif %} |
|
|
|
{%- endif %} |
|
|
|
|
|
|
|
{%- endfor %} |
|
|
|
|
|
|
|
{%- endif %} |
|
|
|
{%- endfor %} |
|
|
|
{%- endif %} |
|
|
|
|
|
|
|
{%- endfor %} |
|
|
|
|
|
|
|
{%- endif %} |