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.

user.sls 1.4KB

9 years ago
9 years ago
9 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. system_user_{{ name }}:
  6. user.present:
  7. - name: {{ name }}
  8. - home: {{ user.home }}
  9. {%- if user.password is defined %}
  10. - password: {{ user.password }}
  11. - enforce_password: true
  12. - gid_from_name: true
  13. {%- endif %}
  14. {%- if user.groups is defined %}
  15. - groups: {{ user.groups }}
  16. {%- endif %}
  17. {%- if user.system is defined and user.system %}
  18. - system: True
  19. {%- else %}
  20. - shell: {{ user.get('shell', '/bin/bash') }}
  21. {%- endif %}
  22. {%- if user.uid is defined and user.uid %}
  23. - uid: {{ user.uid }}
  24. {%- endif %}
  25. system_user_home_{{ user.home }}:
  26. file.directory:
  27. - name: {{ user.home }}
  28. - user: {{ name }}
  29. - mode: 700
  30. - makedirs: true
  31. - require:
  32. - user: system_user_{{ name }}
  33. {%- if user.get('sudo', False) %}
  34. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  35. file.managed:
  36. - source: salt://linux/files/sudoer
  37. - template: jinja
  38. - user: root
  39. - group: root
  40. - mode: 440
  41. - defaults:
  42. user_name: {{ name }}
  43. - require:
  44. - user: system_user_{{ name }}
  45. {%- endif %}
  46. {%- else %}
  47. system_user_{{ name }}:
  48. user.absent:
  49. - name: {{ name }}
  50. system_user_home_{{ user.home }}:
  51. file.absent:
  52. - name: {{ user.home }}
  53. /etc/sudoers.d/90-salt-user-{{ name|replace('.', '-') }}:
  54. file.absent
  55. {%- endif %}
  56. {%- endfor %}
  57. {%- endif %}