New version of salt-formula from Saltstack
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

orchestrate.sls 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. {%- from "salt/map.jinja" import master with context %}
  2. {%- if master.enabled %}
  3. {%- for environment_name, environment in master.get('environment', {}).iteritems() %}
  4. {%- if master.base_environment == environment_name %}
  5. {%- set sorted_priorities = priorities|dictsort(false, 'value') %}
  6. {#- Set debug = True to log simple state result - Fail/True - to /var/log/salt/ on both master and respective minions #}
  7. {%- set debug = False %}
  8. {#- Uncomment to print parsed metadata from formula_name/meta/salt.yml to output file %}
  9. PARSED METADATA:
  10. ---------------
  11. Passed from salt/master/orchestrate.sls
  12. ---
  13. priorities: {{ priorities }}
  14. sorted_priorities: {{ sorted_priorities }}
  15. args: {{ args }}
  16. ---------------
  17. #}
  18. {%- for state in sorted_priorities %}
  19. {%- set formula = state.0.split('.') %}
  20. {%- 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') %}
  21. {{ salt['cmd.shell']('cat /srv/salt/env/'+environment_name+'/'+formula.0+'/orchestrate/'+formula.1+'.sls') }}
  22. {%- else %}
  23. {%- if args[ state.0 ] is defined %}
  24. {{ state.0 }}:
  25. salt.state:
  26. - tgt: '{{ state.0|replace(".", ":") }}'
  27. - tgt_type: pillar
  28. - queue: True
  29. - sls: {{ state.0 }}
  30. {{ args[ state.0 ]|yaml(false)|indent(4) }}
  31. {%- if debug %}
  32. {{ state.0 }}.logok:
  33. salt.function:
  34. - tgt: 'I@salt:master or I@{{ state.0|replace(".", ":") }}'
  35. - tgt_type: compound
  36. - queue: True
  37. - name: cmd.run
  38. - arg:
  39. - 'echo "$(date +"%d %h %Y %H:%M:%S") | state: {{ state.0}} - status: OK" >> /var/log/salt/orchestrate_runner'
  40. - require:
  41. - salt: {{ state.0 }}
  42. {{ state.0 }}.logfail:
  43. salt.function:
  44. - tgt: 'I@salt:master or I@{{ state.0|replace(".", ":") }}'
  45. - tgt_type: compound
  46. - queue: True
  47. - name: cmd.run
  48. - arg:
  49. - 'echo "$(date +"%d %h %Y %H:%M:%S") | state: {{ state.0}} - status: FAIL" >> /var/log/salt/orchestrate_runner'
  50. - onfail:
  51. - salt: {{ state.0 }}
  52. {%- endif %}
  53. {%- else %}
  54. {{ state.0 }}:
  55. salt.state:
  56. - tgt: '{{ state.0|replace(".", ":") }}{%- if "." not in state.0 %}:*{%- endif %}'
  57. - tgt_type: pillar
  58. - queue: True
  59. - sls: {{ state.0 }}
  60. {%- if debug %}
  61. {{ state.0 }}.logok:
  62. salt.function:
  63. - tgt: 'I@salt:master or I@{{ state.0|replace(".", ":") }}'
  64. - tgt_type: compound
  65. - queue: True
  66. - name: cmd.run
  67. - arg:
  68. - 'echo "$(date +"%d %h %Y %H:%M:%S") | state: {{ state.0}} - status: OK" >> /var/log/salt/orchestrate_runner'
  69. - require:
  70. - salt: {{ state.0 }}
  71. {{ state.0 }}.logfail:
  72. salt.function:
  73. - tgt: 'I@salt:master or I@{{ state.0|replace(".", ":") }}'
  74. - tgt_type: compound
  75. - queue: True
  76. - name: cmd.run
  77. - arg:
  78. - 'echo "$(date +"%d %h %Y %H:%M:%S") | state: {{ state.0}} - status: FAIL" >> /var/log/salt/orchestrate_runner'
  79. - onfail:
  80. - salt: {{ state.0 }}
  81. {%- endif %}
  82. {%- endif %}
  83. {%- endif %}
  84. {%- endfor %}
  85. {%- endif %}
  86. {%- endfor %}
  87. {%- endif %}