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.

103 lines
2.2KB

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