Guest User

Untitled

a guest
May 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1.  
  2. #
  3. # Centos doesn't ship with libshadow by default, so we need to add it so we can
  4. # create shadow passwords.
  5. #
  6. package "ruby-shadow"
  7.  
  8. node[:groups].each do |group_key, config|
  9. group group_key do
  10. group_name group_key.to_s
  11. gid config[:gid]
  12. action [:create, :manage]
  13. end
  14. end
  15.  
  16. if node[:active_users]
  17. node[:active_users].each do |username|
  18. config = node[:users][username]
  19. user username do
  20. comment config[:comment]
  21. uid config[:uid]
  22. gid config[:groups].first
  23. home "/home/#{username}"
  24. shell "/bin/bash"
  25. password config[:password]
  26. supports :manage_home => true
  27. action [:create, :manage]
  28. end
  29. end
  30. end
  31.  
  32. node[:active_groups].each do |group_name, config|
  33.  
  34. users = node[:users].find_all { |u| u.last[:groups].include?(group_name) }
  35.  
  36. users.each do |u, config|
  37.  
  38. # puts "setting up #{u}"
  39.  
  40. user u do
  41. comment config[:comment]
  42. uid config[:uid]
  43. gid config[:groups].first
  44. home "/home/#{u}"
  45. shell "/bin/bash"
  46. password config[:password]
  47. supports :manage_home => true
  48. action [:create, :manage]
  49. end
  50.  
  51. # puts "added #{u}"
  52.  
  53. config[:groups].each do |g|
  54. group g do
  55. group_name g.to_s
  56. gid node[:groups][g][:gid]
  57. members [ u ]
  58. append true
  59. action [:modify]
  60. # puts "added group #{g}"
  61. end
  62. end
  63.  
  64. # puts "setting up home directories"
  65. directory "/home/#{u}/.ssh" do
  66. action :create
  67. owner u
  68. group config[:groups].first.to_s
  69. mode 0700
  70. end
  71.  
  72. # puts "setting up public keys for admins"
  73. template "/home/#{u}/.ssh/authorized_keys" do
  74. source "authorized_keys.erb"
  75. action :create
  76. owner u
  77. group config[:groups].first.to_s
  78. # puts node[:ssh_keys][u]
  79. variables(:key => node[:ssh_keys][u])
  80. mode 0600
  81. end
  82. end
  83.  
  84.  
  85. # puts "adding ssh environment variables "
  86. template "/home/#{u}/.ssh/environment" do
  87. source "ssh_environment.erb"
  88. action :create
  89. owner u
  90. group config[:groups].first.to_s
  91. # puts node[:ssh_keys][u]
  92. variables(:key => node[:ssh_environment][u])
  93. mode 0600
  94. end
  95. end
  96.  
  97.  
  98.  
  99. # puts "finished!"
  100.  
  101. end
Add Comment
Please, Sign In to add comment