Advertisement
Guest User

Untitled

a guest
May 2nd, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. formulas/accounts/users.sls:
  2. {% import '_grains/map.jinja' as grain %}
  3. {% from 'accounts/map.jinja' import accounts with context %}
  4.  
  5. {% for username, details in accounts.get('users', {}).items() %}
  6. {% if (details.get('components') is not none and grain.component in details.get('components')) or (details.get('environments') is not none and grain.env in details.get('environments')) or (details.get('environments') is not none and 'all' in details.get('environments')) %}
  7. {{ username }}:
  8. {% if details.get('enabled') == True %}
  9. group.present:
  10. - name: {{ username }}
  11. - gid: {{ details.get('uid') }}
  12. user.present:
  13. - fullname: {{ details.get('fullname') }}
  14. - name: {{ username }}
  15. - shell: {{ details.get('shell','/bin/bash') }}
  16. - home: /home/{{ username }}
  17. - uid: {{ details.get('uid') }}
  18. - gid: {{ details.get('uid') }}
  19. {% if 'groups' in details or details.get('sudo') == True %}
  20. - groups:
  21. {% for group in details.get('groups', []) %}
  22. - {{ group }}
  23. {% endfor %}
  24. {% if details.get('sudo') == True %}
  25. - {{ accounts.sudo.group }}
  26. {% endif %}
  27. {% endif %}
  28.  
  29. {% if 'pubkey' in details %}
  30. file.directory:
  31. - name: /home/{{ username }}/.ssh
  32. - user: {{ username }}
  33. - group: {{ username }}
  34. - mode: 0700
  35. {% endif %}
  36. {% if 'pubkey' in details %}
  37. {{ username }}_authorized_keys_file:
  38. file.managed:
  39. - name: /home/{{ username }}/.ssh/authorized_keys
  40. - user: {{ username }}
  41. - group: {{ username }}
  42. - contents: "{{ details.get('pubkey') }}"
  43. - mode: 0600
  44. {% endif %}
  45. {% else %}
  46. user.absent:
  47. - name: {{ username }}
  48. {% endif %}
  49. {% endif %}
  50. {% endfor %}
  51.  
  52.  
  53. pillars/accounts/init.sls:
  54. accounts:
  55. groups:
  56. admin:
  57. gid: 200
  58. dashboards:
  59. gid: 303
  60. dev:
  61. gid: 301
  62. users:
  63. jsmith:
  64. fullname: John Smith
  65. shell: /bin/bash
  66. uid: 1000
  67. groups:
  68. - admin
  69. pubkey: ssh-rsa <ssh public key> jsmith@acme.com
  70. sudo: True
  71. enabled: True
  72. environments:
  73. - all
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement