public
Description: Capistrano recipes, plugins and templates.
Homepage: http://capitate.rubyforge.org
Clone URL: git://github.com/gabriel/capitate.git
capitate / lib / recipes / centos / centos.rb
100644 45 lines (34 sloc) 1.48 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Custom tasks for centos OS profiles
namespace :centos do
 
  # Add user for an application
  desc <<-DESC
Add user and set user password for application. Adds user to specified groups.
"Source":#{link_to_source(__FILE__)}
DESC
  task_arg(:user_add, "User to add")
  task_arg(:groups, "Groups for user to be in", :default => nil, :example => "\"admin,foo,bar\"")
  task_arg(:home, "Home directory for user", :set => :deploy_to)
  task_arg(:home_readable, "Whether home permissions are readable by all. Needed if using deploy dir as home.", :default => true)
  task :add_user do
    
    adduser_options = []
    adduser_options << "-d #{home}" unless home.blank?
    adduser_options << "-G #{groups}" unless groups.blank?
  
    user_existed = false
    run "id #{user_add} || /usr/sbin/adduser #{adduser_options.join(" ")} #{user_add}" do |channel, stream, data|
      logger.info data
      user_existed = data =~ /uid/
    end
    
    logger.info "User already existed, aborting..." if user_existed
    
    unless user_existed
      run "chmod a+rx #{home}" if home_readable
  
      new_password = prompt.password("Password to set for #{user_add}: ", :verify => true, :lazy => false)
  
      run "passwd #{user_add}" do |channel, stream, data|
        logger.info data
  
        if data =~ /password:/i
          channel.send_data "#{new_password}\n"
          channel.send_data "#{new_password}\n"
        end
      end
    end
        
  end
              
end