Saltstack Official Linux Formula
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

123 líneas
2.8KB

  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. {%- if user.gid is defined and user.gid %}
  35. - gid: {{ user.gid }}
  36. {%- else %}
  37. - gid_from_name: true
  38. {%- endif %}
  39. {%- if user.groups is defined %}
  40. - groups: {{ user.groups }}
  41. {%- endif %}
  42. {%- if user.system is defined and user.system %}
  43. - system: True
  44. - shell: {{ user.get('shell', '/bin/false') }}
  45. {%- else %}
  46. - shell: {{ user.get('shell', '/bin/bash') }}
  47. {%- endif %}
  48. {%- if user.uid is defined and user.uid %}
  49. - uid: {{ user.uid }}
  50. {%- endif %}
  51. {%- if user.unique is defined %}
  52. - unique: {{ user.unique }}
  53. {%- endif %}
  54. {%- if user.maxdays is defined %}
  55. - maxdays: {{ user.maxdays }}
  56. {%- endif %}
  57. {%- if user.mindays is defined %}
  58. - mindays: {{ user.mindays }}
  59. {%- endif %}
  60. {%- if user.warndays is defined %}
  61. - warndays: {{ user.warndays }}
  62. {%- endif %}
  63. {%- if user.inactdays is defined %}
  64. - inactdays: {{ user.inactdays }}
  65. {%- endif %}
  66. - require: {{ requires|yaml }}
  67. system_user_home_{{ user.home }}:
  68. file.directory:
  69. - name: {{ user.home }}
  70. - user: {{ name }}
  71. - mode: {{ user.get('home_dir_mode', 700) }}
  72. - makedirs: true
  73. - require:
  74. - user: system_user_{{ name }}
  75. {%- if user.get('sudo', False) %}
  76. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  77. file.managed:
  78. - source: salt://linux/files/sudoer
  79. - template: jinja
  80. - user: root
  81. - group: root
  82. - mode: 440
  83. - defaults:
  84. user_name: {{ name }}
  85. - require:
  86. - user: system_user_{{ name }}
  87. - check_cmd: /usr/sbin/visudo -c -f
  88. {%- else %}
  89. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  90. file.absent
  91. {%- endif %}
  92. {%- else %}
  93. system_user_{{ name }}:
  94. user.absent:
  95. - name: {{ name }}
  96. system_user_home_{{ user.home }}:
  97. file.absent:
  98. - name: {{ user.home }}
  99. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  100. file.absent
  101. {%- endif %}
  102. {%- endfor %}
  103. {%- endif %}