dust-deploy 0.14.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,21 @@
1
1
  Changelog
2
2
  =============
3
3
 
4
+ 0.15.0
5
+ ------------
6
+
7
+ - node.create_user -> node.migrate_user (supports now more options, make sure to migrate from :home -> 'home' if you use options
8
+ - introduces users recipe
9
+ - removes ssh_authorized_keys in favor of new users recipe (migrate your .yaml files!)
10
+
11
+ recipes:
12
+ users:
13
+ myuser: { ssh_keys: kk, chmod: 0750, authorized_keys: [ user1, user2 ] }
14
+ deploy: { shell: /bin/bash, home: /var/www, ssh_keys: deploy, skel: deploy }
15
+ daemon: { system: true }
16
+ unwanted_user: { remove: true }
17
+
18
+
4
19
  0.14.1
5
20
  ------------
6
21
 
@@ -9,7 +9,7 @@ class Chrony < Recipe
9
9
  end
10
10
 
11
11
  # install package
12
- @node.install_package('chrony')
12
+ return false unless @node.install_package('chrony')
13
13
 
14
14
  # set config file and service name according to distribution used
15
15
  if @node.uses_apt?
@@ -52,9 +52,9 @@ class Chrony < Recipe
52
52
  'logdir' => '/var/log/chrony',
53
53
  'logchange' => 0.5,
54
54
  'maxupdateskew' => 100.0, # Stop bad estimates upsetting machine clock.
55
- 'dumponexit' => '', # Dump measurements when daemon exits.
56
- 'dumpdir' => '/var/lib/chrony',
57
- 'rtconutc' => '' # CMOS clock is on UTC (GMT)
55
+ # 'dumponexit' => '', # Dump measurements when daemon exits.
56
+ # 'dumpdir' => '/var/lib/chrony',
57
+ # 'rtconutc' => '' # CMOS clock is on UTC (GMT)
58
58
  }
59
59
 
60
60
  if @node.uses_rpm?
@@ -11,21 +11,23 @@ class Cjdroute< Recipe
11
11
 
12
12
  # clean up building directory, if --restart is given
13
13
  # using --restart, since there's no --cleanup
14
- return unless make_clean if @options.restart?
14
+ # return unless make_clean if @options.restart?
15
15
 
16
16
  # compiling action
17
17
  return unless run_make
18
18
 
19
- stop_cjdroute
20
-
21
- # copy binary
22
- return unless @node.mkdir @config['bin_dir']
23
- return unless @node.cp "#{@config['build_dir']}/build/cjdroute", "#{@config['bin_dir']}/cjdroute"
24
-
25
19
  # create the config file and place it into etc_dir
26
20
  return unless generate_config
27
21
 
28
- start_cjdroute
22
+ if options.restart?
23
+ stop_cjdroute
24
+
25
+ # copy binary
26
+ return unless @node.mkdir @config['bin_dir']
27
+ return unless @node.cp "#{@config['build_dir']}/build/cjdroute", "#{@config['bin_dir']}/cjdroute"
28
+
29
+ start_cjdroute
30
+ end
29
31
  end
30
32
 
31
33
 
@@ -0,0 +1,75 @@
1
+ class Users < Recipe
2
+
3
+ desc 'users:deploy', 'creates users and user settings (incl. ssh keys)'
4
+ def deploy
5
+ @config.each do |user, options|
6
+ # just create the user, without any arguments
7
+ options = {} if options.nil? or options.is_a? TrueClass
8
+ next unless @node.manage_user(user, options)
9
+
10
+ # don't deploy anything if the user just has been removed
11
+ unless options['remove']
12
+ deploy_ssh_keys(user, options['ssh_keys']) if options['ssh_keys']
13
+ deploy_authorized_keys(user, options['authorized_keys']) if options['authorized_keys']
14
+ end
15
+ end
16
+ end
17
+
18
+
19
+ private
20
+
21
+ # deploys ssh keys to users homedir
22
+ def deploy_ssh_keys(user, key_dir)
23
+ ssh_dir = create_ssh_dir(user)
24
+ @node.messages.add("deploying ssh keys for #{user}\n")
25
+
26
+ Dir["#{@template_path}/#{key_dir}/*"].each do |file|
27
+ destination = "#{ssh_dir}/#{File.basename(file)}"
28
+ @node.scp(file, destination, :indent => 2)
29
+ @node.chown("#{user}:#{user}", destination)
30
+
31
+ # chmod private key
32
+ if File.basename(file) =~ /^(id_rsa|id_dsa|id_ecdsa)$/
33
+ msg = @node.messages.add('setting private key access to 0600', :indent => 3)
34
+ msg.parse_result(@node.chmod('0600', destination, :quiet => true))
35
+ end
36
+ end
37
+ end
38
+
39
+ # generates and deploy authorized_keys to users homedir
40
+ def deploy_authorized_keys(user, ssh_users)
41
+ @node.messages.add("generating authorized_keys for #{user}\n")
42
+ ssh_dir = create_ssh_dir(user)
43
+ authorized_keys = generate_authorized_keys(ssh_users)
44
+ @node.write("#{ssh_dir}/authorized_keys", authorized_keys)
45
+ @node.chown("#{user}:#{user}", "#{ssh_dir}/authorized_keys")
46
+ end
47
+
48
+ def create_ssh_dir(user)
49
+ ssh_dir = @node.get_home(user) + '/.ssh'
50
+ @node.mkdir(ssh_dir)
51
+ @node.chown("#{user}:#{user}", ssh_dir)
52
+ ssh_dir
53
+ end
54
+
55
+ def generate_authorized_keys(ssh_users)
56
+ # load users and their ssh keys from yaml file
57
+ users = YAML.load_file("#{@template_path}/public_keys.yaml")
58
+ authorized_keys = ''
59
+
60
+ # create the authorized_keys hash for this user
61
+ ssh_users.to_array.each do |ssh_user|
62
+ users[ssh_user]['name'] ||= ssh_user
63
+ msg = @node.messages.add("adding user #{users[ssh_user]['name']}", :indent => 2)
64
+ users[ssh_user]['keys'].each do |key|
65
+ authorized_keys << "#{key}"
66
+ authorized_keys << " #{users[ssh_user]['name']}" if users[ssh_user]['name']
67
+ authorized_keys << " <#{users[ssh_user]['email']}>" if users[ssh_user]['email']
68
+ authorized_keys << "\n"
69
+ end
70
+ msg.ok
71
+ end
72
+
73
+ authorized_keys
74
+ end
75
+ end
@@ -713,19 +713,48 @@ module Dust
713
713
  msg.parse_result(exec("id #{user}")[:exit_code])
714
714
  end
715
715
 
716
- # create a user
717
- def create_user user, options = {}
718
- options = default_options.merge options
719
- options[:home] ||= nil
720
- options[:shell] ||= nil
716
+ # manages users (create, modify)
717
+ def manage_user(user, options = {})
718
+ options = default_options.merge(options)
719
+ options = { 'home' => nil, 'shell' => nil, 'uid' => nil, 'remove' => false,
720
+ 'gid' => nil, 'groups' => nil, 'system' => false }.merge(options)
721
+
722
+ # delete user from system
723
+ if options['remove']
724
+ if user_exists?(user, :quiet => true)
725
+ msg = messages.add("deleting user #{user} from system", :indent => options[:indent])
726
+ return msg.parse_result(exec("userdel --remove #{user}")[:exit_code])
727
+ end
728
+
729
+ return messages.add("user #{user} not present in system").ok
730
+ end
721
731
 
722
- return true if user_exists? user, options
732
+ if user_exists?(user, :quiet => true)
733
+ args = ""
734
+ args << " --move-home --home #{options['home']}" if options['home']
735
+ args << " --shell #{options['shell']}" if options['shell']
736
+ args << " --uid #{options['uid']}" if options['uid']
737
+ args << " --gid #{options['gid']}" if options['gid']
738
+ args << " --append --groups #{Array(options['groups']).join(',')}" if options['groups']
739
+
740
+ unless args.empty?
741
+ msg = messages.add("modifying user #{user}", :indent => options[:indent])
742
+ return msg.parse_result(exec("usermod #{user} #{args}")[:exit_code])
743
+ end
723
744
 
724
- msg = messages.add("creating user #{user}", :indent => options[:indent])
725
- cmd = "useradd #{user} -m"
726
- cmd += " -d #{options[:home]}" if options[:home]
727
- cmd += " -s #{options[:shell]}" if options[:shell]
728
- msg.parse_result(exec(cmd)[:exit_code])
745
+ else
746
+ args = ""
747
+ args = "--create-home" unless options['system']
748
+ args << " --system" if options['system']
749
+ args << " --home #{options['home']}" if options['home'] and not options['system']
750
+ args << " --shell #{options['shell']}" if options['shell']
751
+ args << " --uid #{options['uid']}" if options['uid']
752
+ args << " --gid #{options['gid']}" if options['gid']
753
+ args << " --groups #{Array(options['groups']).join(',')}" if options['groups']
754
+
755
+ msg = messages.add("creating user #{user}", :indent => options[:indent])
756
+ return msg.parse_result(exec("useradd #{user} #{args}")[:exit_code])
757
+ end
729
758
  end
730
759
 
731
760
  # returns the home directory of this user
@@ -1,3 +1,3 @@
1
1
  module Dust
2
- VERSION = "0.14.1"
2
+ VERSION = "0.15.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dust-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.15.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-24 00:00:00.000000000 Z
12
+ date: 2012-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -199,11 +199,11 @@ files:
199
199
  - lib/dust/recipes/resolv_conf.rb
200
200
  - lib/dust/recipes/ruby_rvm.rb
201
201
  - lib/dust/recipes/skel.rb
202
- - lib/dust/recipes/ssh_authorized_keys.rb
203
202
  - lib/dust/recipes/ssh_config.rb
204
203
  - lib/dust/recipes/sshd.rb
205
204
  - lib/dust/recipes/sudoers.rb
206
205
  - lib/dust/recipes/sysctl.rb
206
+ - lib/dust/recipes/users.rb
207
207
  - lib/dust/recipes/zabbix_agent.rb
208
208
  - lib/dust/runner.rb
209
209
  - lib/dust/server.rb
@@ -1,69 +0,0 @@
1
- require 'yaml'
2
-
3
- class SshAuthorizedKeys < Recipe
4
- desc 'ssh_authorized_keys:deploy', 'configures ssh authorized_keys'
5
- def deploy
6
-
7
- @config.each do |remote_user, ssh_users|
8
- @node.messages.add("generating authorized_keys for #{remote_user}\n")
9
- authorized_keys = generate_authorized_keys ssh_users
10
- deploy_authorized_keys remote_user, authorized_keys
11
- end
12
- end
13
-
14
-
15
- private
16
-
17
- def generate_authorized_keys ssh_users
18
- # load users and their ssh keys from yaml file
19
- users = YAML.load_file "#{@template_path}/users.yaml"
20
- authorized_keys = ''
21
-
22
- # create the authorized_keys hash for this user
23
- ssh_users.to_array.each do |ssh_user|
24
- users[ssh_user]['name'] ||= ssh_user
25
- msg = @node.messages.add("adding user #{users[ssh_user]['name']}", :indent => 2)
26
- users[ssh_user]['keys'].each do |key|
27
- authorized_keys << "#{key}"
28
- authorized_keys << " #{users[ssh_user]['name']}" if users[ssh_user]['name']
29
- authorized_keys << " <#{users[ssh_user]['email']}>" if users[ssh_user]['email']
30
- authorized_keys << "\n"
31
- end
32
- msg.ok
33
- end
34
-
35
- authorized_keys
36
- end
37
-
38
- # deploy the authorized_keys file for this user
39
- # creating user if not existent
40
- def deploy_authorized_keys user, authorized_keys
41
- # create user, if not existent
42
- return unless @node.create_user user
43
-
44
- home = @node.get_home user
45
- # check and create necessary directories
46
- return unless @node.mkdir("#{home}/.ssh")
47
-
48
- # deploy authorized_keys
49
- return unless @node.write "#{home}/.ssh/authorized_keys", authorized_keys
50
-
51
- # check permissions
52
- @node.chown "#{user}:#{user}", "#{home}/.ssh"
53
- end
54
-
55
- # remove authorized_keys files for all other users
56
- # TODO: add this option
57
- def cleanup
58
- if options.cleanup?
59
- @node.messages.add("deleting other authorized_keys files\n")
60
- @node.get_system_users(:quiet => true).each do |user|
61
- next if users.keys.include? user
62
- home = @node.get_home user
63
- if @node.file_exists? "#{home}/.ssh/authorized_keys", :quiet => true
64
- @node.rm "#{home}/.ssh/authorized_keys", :indent => 2
65
- end
66
- end
67
- end
68
- end
69
- end