Saltstack Official Logrotate 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.

config.sls 2.0KB

fix: make necessary modifications to get working on `salt-ssh` * https://freenode.logbot.info/saltstack-formulas/20200506#c3811885-c3812572 * Avoid `defaults.merge` * Send template values by `context`, to avoid: ```python ID: logrotate-config Function: file.managed Name: /etc/logrotate.conf Result: False Comment: An exception occurred in this state: Traceback (most recent call last): File "/var/tmp/.root_08c4d3_salt/pyall/salt/utils/templates.py", line 394, in render_jinja_tmpl output = template.render(**decoded_context) File "/var/tmp/.root_08c4d3_salt/pyall/jinja2/environment.py", line 1008, in render return self.environment.handle_exception(exc_info, True) File "/var/tmp/.root_08c4d3_salt/pyall/jinja2/environment.py", line 780, in handle_exception reraise(exc_type, exc_value, tb) File "/var/tmp/.root_08c4d3_salt/pyall/jinja2/_compat.py", line 37, in reraise raise value.with_traceback(tb) File "<template>", line 1, in top-level template code File "/var/tmp/.root_08c4d3_salt/pyall/salt/utils/jinja.py", line 193, in get_source raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: logrotate/map.jinja During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/var/tmp/.root_08c4d3_salt/pyall/salt/state.py", line 1981, in call **cdata['kwargs']) File "/var/tmp/.root_08c4d3_salt/pyall/salt/loader.py", line 1977, in wrapper return f(*args, **kwargs) File "/var/tmp/.root_08c4d3_salt/pyall/salt/states/file.py", line 3037, in managed **kwargs File "/var/tmp/.root_08c4d3_salt/pyall/salt/modules/file.py", line 4846, in check_managed_changes **kwargs) File "/var/tmp/.root_08c4d3_salt/pyall/salt/modules/file.py", line 4287, in get_managed **kwargs) File "/var/tmp/.root_08c4d3_salt/pyall/salt/utils/templates.py", line 169, in render_tmpl output = render_str(tmplstr, context, tmplpath) File "/var/tmp/.root_08c4d3_salt/pyall/salt/utils/templates.py", line 443, in render_jinja_tmpl trace=tracestr) salt.exceptions.SaltRenderError: Jinja error: logrotate/map.jinja Traceback (most recent call last): File "/var/tmp/.root_08c4d3_salt/pyall/salt/utils/templates.py", line 394, in render_jinja_tmpl output = template.render(**decoded_context) File "/var/tmp/.root_08c4d3_salt/pyall/jinja2/environment.py", line 1008, in render return self.environment.handle_exception(exc_info, True) File "/var/tmp/.root_08c4d3_salt/pyall/jinja2/environment.py", line 780, in handle_exception reraise(exc_type, exc_value, tb) File "/var/tmp/.root_08c4d3_salt/pyall/jinja2/_compat.py", line 37, in reraise raise value.with_traceback(tb) File "<template>", line 1, in top-level template code File "/var/tmp/.root_08c4d3_salt/pyall/salt/utils/jinja.py", line 193, in get_source raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: logrotate/map.jinja ; line 1 --- {%- from "logrotate/map.jinja" import logrotate with context -%} <====================== {%- set config = salt['pillar.get']('logrotate:default_config', logrotate.default_config) -%} {%- set processed_parameters = [] -%} {%- macro set_parameter(parameter, default=None) -%} [...] ```
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. {% from "logrotate/map.jinja" import logrotate with context %}
  2. include:
  3. - logrotate
  4. {% set ns = namespace(hourly=False) %}
  5. {% for key, value in logrotate.jobs.items() %}
  6. {% set contents = value.get('contents', False) %}
  7. {% if 'hourly' in (contents or value.config) %}
  8. {% set ns.hourly = True %}
  9. {% break %}
  10. {% endif %}
  11. {% endfor %}
  12. logrotate-config:
  13. file.managed:
  14. - name: {{ logrotate.conf_file }}
  15. - source: salt://logrotate/templates/logrotate.conf.tmpl
  16. - template: jinja
  17. - user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
  18. - group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
  19. - mode: {{ salt['config.get']('logrotate:config:mode', '0644') }}
  20. - context:
  21. logrotate: {{ logrotate|tojson }}
  22. logrotate-directory:
  23. file.directory:
  24. - name: {{ logrotate.include_dir }}
  25. - user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
  26. - group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
  27. - mode: '0755'
  28. - makedirs: True
  29. {%- if ns.hourly %}
  30. logrotate-hourly-config:
  31. file.managed:
  32. - name: {{ logrotate.hourly_conf_file }}
  33. - user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
  34. - group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
  35. - mode: {{ salt['config.get']('logrotate:config:mode', '0644') }}
  36. - contents:
  37. - include {{ logrotate.hourly_include_dir }}
  38. logrotate-hourly-directory:
  39. file.directory:
  40. - name: {{ logrotate.hourly_include_dir }}
  41. - user: {{ logrotate.user }}
  42. - group: {{ logrotate.group }}
  43. - mode: '0755'
  44. - makedirs: True
  45. logrotate-hourly-cron:
  46. file.managed:
  47. - name: "/etc/cron.hourly/logrotate"
  48. - source: salt://logrotate/templates/logrotate.hourly.tmpl
  49. - template: jinja
  50. - user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
  51. - group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
  52. - mode: '0775'
  53. - context:
  54. logrotate: {{ logrotate|tojson }}
  55. {%- endif %}