Saltstack Official Linux Formula
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

116 行
2.6KB

  1. {%- from "linux/map.jinja" import system with context %}
  2. {%- if system.enabled %}
  3. include:
  4. - linux.system.group
  5. {%- for name, user in system.user.items() %}
  6. {%- if user.enabled %}
  7. {%- set requires = [] %}
  8. {%- for group in user.get('groups', []) %}
  9. {%- if group in system.get('group', {}).keys() %}
  10. {%- do requires.append({'group': 'system_group_'+group}) %}
  11. {%- endif %}
  12. {%- endfor %}
  13. {%- if user.gid is not defined %}
  14. system_group_{{ name }}:
  15. group.present:
  16. - name: {{ name }}
  17. - require_in:
  18. - user: system_user_{{ name }}
  19. {%- endif %}
  20. system_user_{{ name }}:
  21. user.present:
  22. - name: {{ name }}
  23. - home: {{ user.home }}
  24. {% if user.get('password') == False %}
  25. - enforce_password: false
  26. {% elif user.get('password') == None %}
  27. - enforce_password: true
  28. - password: '*'
  29. {% elif user.get('password') %}
  30. - enforce_password: true
  31. - password: {{ user.password }}
  32. - hash_password: {{ user.get('hash_password', False) }}
  33. {% endif %}
  34. - gid_from_name: true
  35. {%- if user.groups is defined %}
  36. - groups: {{ user.groups }}
  37. {%- endif %}
  38. {%- if user.system is defined and user.system %}
  39. - system: True
  40. - shell: {{ user.get('shell', '/bin/false') }}
  41. {%- else %}
  42. - shell: {{ user.get('shell', '/bin/bash') }}
  43. {%- endif %}
  44. {%- if user.uid is defined and user.uid %}
  45. - uid: {{ user.uid }}
  46. {%- endif %}
  47. {%- if user.maxdays is defined %}
  48. - maxdays: {{ user.maxdays }}
  49. {%- endif %}
  50. {%- if user.mindays is defined %}
  51. - mindays: {{ user.mindays }}
  52. {%- endif %}
  53. {%- if user.warndays is defined %}
  54. - warndays: {{ user.warndays }}
  55. {%- endif %}
  56. {%- if user.inactdays is defined %}
  57. - inactdays: {{ user.inactdays }}
  58. {%- endif %}
  59. - require: {{ requires|yaml }}
  60. system_user_home_{{ user.home }}:
  61. file.directory:
  62. - name: {{ user.home }}
  63. - user: {{ name }}
  64. - mode: {{ user.get('home_dir_mode', 700) }}
  65. - makedirs: true
  66. - require:
  67. - user: system_user_{{ name }}
  68. {%- if user.get('sudo', False) %}
  69. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  70. file.managed:
  71. - source: salt://linux/files/sudoer
  72. - template: jinja
  73. - user: root
  74. - group: root
  75. - mode: 440
  76. - defaults:
  77. user_name: {{ name }}
  78. - require:
  79. - user: system_user_{{ name }}
  80. - check_cmd: /usr/sbin/visudo -c -f
  81. {%- else %}
  82. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  83. file.absent
  84. {%- endif %}
  85. {%- else %}
  86. system_user_{{ name }}:
  87. user.absent:
  88. - name: {{ name }}
  89. system_user_home_{{ user.home }}:
  90. file.absent:
  91. - name: {{ user.home }}
  92. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  93. file.absent
  94. {%- endif %}
  95. {%- endfor %}
  96. {%- endif %}