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

86 lines
2.5KB

  1. {%- from "linux/map.jinja" import system with context %}
  2. {%- if system.enabled %}
  3. {%- if system.kernel is defined %}
  4. {%- set kernel_boot_opts = [] %}
  5. {%- do kernel_boot_opts.append('isolcpus=' ~ system.kernel.isolcpu) if system.kernel.isolcpu is defined %}
  6. {%- do kernel_boot_opts.append('elevator=' ~ system.kernel.elevator) if system.kernel.elevator is defined %}
  7. {%- do kernel_boot_opts.extend(system.kernel.boot_options) if system.kernel.boot_options is defined %}
  8. {%- if kernel_boot_opts %}
  9. include:
  10. - linux.system.grub
  11. /etc/default/grub.d/99-custom-settings.cfg:
  12. file.managed:
  13. - contents: 'GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT {{ kernel_boot_opts|join(' ') }}"'
  14. - require:
  15. - file: grub_d_directory
  16. {%- if grains.get('virtual_subtype', None) not in ['Docker', 'LXC'] %}
  17. - watch_in:
  18. - cmd: grub_update
  19. {%- endif %}
  20. {%- endif %}
  21. {%- if system.kernel.version is defined %}
  22. linux_kernel_package:
  23. pkg.installed:
  24. - pkgs:
  25. - linux-image-{{ system.kernel.version }}-{{ system.kernel.type|default('generic') }}
  26. {%- if system.kernel.get('headers', False) %}
  27. - linux-headers-{{ system.kernel.version }}-{{ system.kernel.type|default('generic') }}
  28. {%- endif %}
  29. {%- if system.kernel.get('extra', False) %}
  30. - linux-image-extra-{{ system.kernel.version }}-{{ system.kernel.type|default('generic') }}
  31. {%- endif %}
  32. - refresh: true
  33. # Not very Salt-ish.. :-(
  34. linux_kernel_old_absent:
  35. cmd.wait:
  36. - name: "dpkg -l '*linux-generic-*[0-9]*' '*linux-image-*[0-9]*' '*linux-headers-*[0-9]*' '*linux-image-extra-*[0-9]*' | grep -E '^ii' | awk '{print $2}' | grep -v '{{ system.kernel.version }}' | xargs dpkg --purge --force-depends"
  37. - watch:
  38. - pkg: linux_kernel_package
  39. {%- endif %}
  40. {%- for module in system.kernel.get('modules', []) %}
  41. linux_kernel_module_{{ module }}:
  42. kmod.present:
  43. - name: {{ module }}
  44. - persist: true
  45. {%- endfor %}
  46. {%- for module_name, module_content in system.kernel.get('module', {}).items() %}
  47. /etc/modprobe.d/{{ module_name }}.conf:
  48. file.managed:
  49. - user: root
  50. - group: root
  51. - mode: 0644
  52. - template: jinja
  53. - source: salt://linux/files/modprobe.conf.jinja
  54. - defaults:
  55. module_content: {{ module_content }}
  56. module_name: {{ module_name }}
  57. {%- endfor %}
  58. {%- for sysctl_name, sysctl_value in system.kernel.get('sysctl', {}).items() %}
  59. linux_kernel_{{ sysctl_name }}:
  60. sysctl.present:
  61. - name: {{ sysctl_name }}
  62. - value: {{ sysctl_value }}
  63. {%- endfor %}
  64. {%- endif %}
  65. {%- endif %}