Saltstack Official Apache Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.0KB

  1. {% if grains['os_family']=="Debian" %}
  2. include:
  3. - apache
  4. {%- set existing_states = salt['cp.list_states']() %}
  5. {%- for module in salt['pillar.get']('apache:modules:enabled', []) %}
  6. {%- set mod_state = 'apache.mod_{}'.format(module) %}
  7. {%- if mod_state in existing_states %}
  8. - {{ mod_state }}
  9. {%- endif %}
  10. {%- endfor %}
  11. {% for module in salt['pillar.get']('apache:modules:enabled', []) %}
  12. {% if module not in existing_states %}
  13. a2enmod {{ module }}:
  14. cmd.run:
  15. - unless: ls /etc/apache2/mods-enabled/{{ module }}.load
  16. - order: 225
  17. - require:
  18. - pkg: apache
  19. - watch_in:
  20. - module: apache-restart
  21. - require_in:
  22. - module: apache-restart
  23. - module: apache-reload
  24. - service: apache
  25. {% endif %}
  26. {% endfor %}
  27. {% for module in salt['pillar.get']('apache:modules:disabled', []) %}
  28. a2dismod -f {{ module }}:
  29. cmd.run:
  30. - onlyif: ls /etc/apache2/mods-enabled/{{ module }}.load
  31. - order: 225
  32. - require:
  33. - pkg: apache
  34. - watch_in:
  35. - module: apache-restart
  36. - require_in:
  37. - module: apache-restart
  38. - module: apache-reload
  39. - service: apache
  40. {% endfor %}
  41. {% elif grains['os_family']=="RedHat" %}
  42. include:
  43. - apache
  44. {% for module in salt['pillar.get']('apache:modules:enabled', []) %}
  45. find /etc/httpd/ -name '*.conf' -type f -exec sed -i -e 's/\(^#\)\(\s*LoadModule.{{ module }}_module\)/\2/g' {} \;:
  46. cmd.run:
  47. - unless: httpd -M 2> /dev/null | grep "[[:space:]]{{ module }}_module"
  48. - order: 225
  49. - require:
  50. - pkg: apache
  51. - watch_in:
  52. - module: apache-restart
  53. - require_in:
  54. - module: apache-restart
  55. - module: apache-reload
  56. - service: apache
  57. {% endfor %}
  58. {% for module in salt['pillar.get']('apache:modules:disabled', []) %}
  59. find /etc/httpd/ -name '*.conf' -type f -exec sed -i -e 's/\(^\s*LoadModule.{{ module }}_module\)/#\1/g' {} \;:
  60. cmd.run:
  61. - onlyif: httpd -M 2> /dev/null | grep "[[:space:]]{{ module }}_module"
  62. - order: 225
  63. - require:
  64. - pkg: apache
  65. - watch_in:
  66. - module: apache-restart
  67. - require_in:
  68. - module: apache-restart
  69. - module: apache-reload
  70. - service: apache
  71. {% endfor %}
  72. {% elif salt['grains.get']('os_family') == 'Suse' or salt['grains.get']('os') == 'SUSE' %}
  73. include:
  74. - apache
  75. {% for module in salt['pillar.get']('apache:modules:enabled', []) %}
  76. a2enmod {{ module }}:
  77. cmd.run:
  78. - unless: egrep "^APACHE_MODULES=" /etc/sysconfig/apache2 | grep {{ module }}
  79. - order: 225
  80. - require:
  81. - pkg: apache
  82. - watch_in:
  83. - module: apache-restart
  84. - require_in:
  85. - module: apache-restart
  86. - module: apache-reload
  87. - service: apache
  88. {% endfor %}
  89. {% for module in salt['pillar.get']('apache:modules:disabled', []) %}
  90. a2dismod -f {{ module }}:
  91. cmd.run:
  92. - onlyif: egrep "^APACHE_MODULES=" /etc/sysconfig/apache2 | grep {{ module }}
  93. - order: 225
  94. - require:
  95. - pkg: apache
  96. - watch_in:
  97. - module: apache-restart
  98. - require_in:
  99. - module: apache-restart
  100. - module: apache-reload
  101. - service: apache
  102. {% endfor %}
  103. {% endif %}