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.

89 lines
1.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.iteritems() %}
  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. system_user_{{ name }}:
  14. user.present:
  15. - name: {{ name }}
  16. - home: {{ user.home }}
  17. {%- if user.password is defined %}
  18. - password: {{ user.password }}
  19. - enforce_password: true
  20. - gid_from_name: true
  21. {%- endif %}
  22. {%- if user.groups is defined %}
  23. - groups: {{ user.groups }}
  24. {%- endif %}
  25. {%- if user.system is defined and user.system %}
  26. - system: True
  27. {%- else %}
  28. - shell: {{ user.get('shell', '/bin/bash') }}
  29. {%- endif %}
  30. {%- if user.uid is defined and user.uid %}
  31. - uid: {{ user.uid }}
  32. {%- endif %}
  33. - require: {{ requires|yaml }}
  34. system_user_home_{{ user.home }}:
  35. file.directory:
  36. - name: {{ user.home }}
  37. - user: {{ name }}
  38. - mode: 700
  39. - makedirs: true
  40. - require:
  41. - user: system_user_{{ name }}
  42. {%- if user.get('sudo', False) %}
  43. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  44. file.managed:
  45. - source: salt://linux/files/sudoer
  46. - template: jinja
  47. - user: root
  48. - group: root
  49. - mode: 440
  50. - defaults:
  51. user_name: {{ name }}
  52. - require:
  53. - user: system_user_{{ name }}
  54. - check_cmd: /usr/sbin/visudo -c -f
  55. {%- else %}
  56. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  57. file.absent
  58. {%- endif %}
  59. {%- else %}
  60. system_user_{{ name }}:
  61. user.absent:
  62. - name: {{ name }}
  63. system_user_home_{{ user.home }}:
  64. file.absent:
  65. - name: {{ user.home }}
  66. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  67. file.absent
  68. {%- endif %}
  69. {%- endfor %}
  70. {%- endif %}