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.

87 lines
1.8KB

  1. {%- from "linux/map.jinja" import system with context %}
  2. {%- if system.enabled %}
  3. {%- for name, user in system.user.iteritems() %}
  4. {%- if user.enabled %}
  5. {%- set requires = [] %}
  6. {%- for group in user.get('groups', []) %}
  7. {%- if group in system.get('group', {}).keys() %}
  8. {%- do requires.append({'group': 'system_group_'+group}) %}
  9. {%- endif %}
  10. {%- endfor %}
  11. system_user_{{ name }}:
  12. user.present:
  13. - name: {{ name }}
  14. - home: {{ user.home }}
  15. {%- if user.password is defined %}
  16. - password: {{ user.password }}
  17. - enforce_password: true
  18. - gid_from_name: true
  19. {%- endif %}
  20. {%- if user.groups is defined %}
  21. - groups: {{ user.groups }}
  22. {%- endif %}
  23. {%- if user.system is defined and user.system %}
  24. - system: True
  25. {%- else %}
  26. - shell: {{ user.get('shell', '/bin/bash') }}
  27. {%- endif %}
  28. {%- if user.uid is defined and user.uid %}
  29. - uid: {{ user.uid }}
  30. {%- endif %}
  31. - require: {{ requires|yaml }}
  32. system_user_home_{{ user.home }}:
  33. file.directory:
  34. - name: {{ user.home }}
  35. - user: {{ name }}
  36. - mode: 700
  37. - makedirs: true
  38. - require:
  39. - user: system_user_{{ name }}
  40. {%- if user.get('sudo', False) %}
  41. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  42. file.managed:
  43. - source: salt://linux/files/sudoer
  44. - template: jinja
  45. - user: root
  46. - group: root
  47. - mode: 440
  48. - defaults:
  49. user_name: {{ name }}
  50. - require:
  51. - user: system_user_{{ name }}
  52. - check_cmd: /usr/sbin/visudo -c -f
  53. {%- else %}
  54. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  55. file.absent
  56. {%- endif %}
  57. {%- else %}
  58. system_user_{{ name }}:
  59. user.absent:
  60. - name: {{ name }}
  61. system_user_home_{{ user.home }}:
  62. file.absent:
  63. - name: {{ user.home }}
  64. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  65. file.absent
  66. {%- endif %}
  67. {%- endfor %}
  68. {%- endif %}