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.

104 lines
2.3KB

  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. - require: {{ requires|yaml }}
  48. system_user_home_{{ user.home }}:
  49. file.directory:
  50. - name: {{ user.home }}
  51. - user: {{ name }}
  52. - mode: {{ user.get('home_dir_mode', 700) }}
  53. - makedirs: true
  54. - require:
  55. - user: system_user_{{ name }}
  56. {%- if user.get('sudo', False) %}
  57. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  58. file.managed:
  59. - source: salt://linux/files/sudoer
  60. - template: jinja
  61. - user: root
  62. - group: root
  63. - mode: 440
  64. - defaults:
  65. user_name: {{ name }}
  66. - require:
  67. - user: system_user_{{ name }}
  68. - check_cmd: /usr/sbin/visudo -c -f
  69. {%- else %}
  70. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  71. file.absent
  72. {%- endif %}
  73. {%- else %}
  74. system_user_{{ name }}:
  75. user.absent:
  76. - name: {{ name }}
  77. system_user_home_{{ user.home }}:
  78. file.absent:
  79. - name: {{ user.home }}
  80. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  81. file.absent
  82. {%- endif %}
  83. {%- endfor %}
  84. {%- endif %}