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.

98 lines
2.1KB

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