dust-deploy 0.12.2 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,18 +3,17 @@ class Redis < Recipe
3
3
  def deploy
4
4
  @node.install_package 'redis-server'
5
5
  @node.write '/etc/redis/redis.conf', generate_redis_conf
6
- configure_sysctl
7
6
  @node.restart_service 'redis-server' if @options.restart
8
7
  end
9
8
 
10
9
  desc 'redis:status', 'displays redis-cli info'
11
10
  def status
12
11
  return false unless @node.package_installed? 'redis-server'
13
- ::Dust.print_msg 'running "redis-cli info"'
12
+ msg = @node.messages.add('running "redis-cli info"')
14
13
  ret = @node.exec 'redis-cli info'
15
- ::Dust.print_result ret[:exit_code]
14
+ msg.parse_result(ret[:exit_code])
16
15
 
17
- ::Dust.print_msg ret[:stdout], :indent => 0 unless ret[:stdout].empty?
16
+ @node.messages.add(ret[:stdout], :indent => 0) unless ret[:stdout].empty?
18
17
  end
19
18
 
20
19
 
@@ -71,25 +70,4 @@ class Redis < Recipe
71
70
 
72
71
  redis_conf
73
72
  end
74
-
75
- # redis complains if vm.overcommit_memory != 1
76
- def configure_sysctl
77
- if @node.uses_apt?
78
- ::Dust.print_msg "setting redis sysctl keys\n"
79
-
80
- ::Dust.print_msg 'setting overcommit memory to 1', :indent => 2
81
- ::Dust.print_result @node.exec('sysctl -w vm.overcommit_memory=1')[:exit_code]
82
- ::Dust.print_msg 'setting swappiness to 0', :indent => 2
83
- ::Dust.print_result @node.exec('sysctl -w vm.swappiness=0')[:exit_code]
84
-
85
- file = ''
86
- file << "vm.overcommit_memory=1\n"
87
- file << "vm.swappiness=0\n"
88
-
89
- @node.write "/etc/sysctl.d/30-redis.conf", file
90
-
91
- else
92
- ::Dust.print_warning 'sysctl configuration not supported for your os'
93
- end
94
- end
95
73
  end
@@ -5,22 +5,21 @@ class Repositories < Recipe
5
5
 
6
6
  delete_old_repositories
7
7
  deploy_repositories
8
-
8
+
9
9
  # fetch new stuff
10
- puts
11
- @node.update_repos if options.restart? or options.reload?
10
+ @node.update_repos if options.restart? or options.reload?
12
11
  end
13
-
14
-
12
+
13
+
15
14
  private
16
-
15
+
17
16
  # deletes all .list files under /etc/apt/sources.list.d
18
17
  def delete_old_repositories
19
- :: Dust.print_msg 'deleting old repositories'
18
+ msg = @node.messages.add('deleting old repositories')
20
19
  @node.rm '/etc/apt/sources.list.d/*.list', :quiet => true if @node.uses_apt?
21
- ::Dust.print_ok
20
+ msg.ok
22
21
  end
23
-
22
+
24
23
  def deploy_repositories
25
24
  @config.each do |name, repo|
26
25
 
@@ -28,16 +27,16 @@ class Repositories < Recipe
28
27
  repo = {} unless repo.is_a? Hash
29
28
 
30
29
  merge_with_default_settings repo
31
-
30
+
32
31
  # the default repository in /etc/apt/sources.list (debian)
33
32
  if name == 'default'
34
- ::Dust.print_msg 'deploying default repository'
35
- sources = generate_default_repo repo
36
- ::Dust.print_result @node.write('/etc/apt/sources.list', sources, :quiet => true)
33
+ msg = @node.messages.add('deploying default repository' )
34
+ sources = generate_default_repo repo
35
+ msg.parse_result(@node.write('/etc/apt/sources.list', sources, :quiet => true) )
37
36
  else
38
- ::Dust.print_msg "adding repository '#{name}' to sources"
37
+ msg = @node.messages.add("adding repository '#{name}' to sources" )
39
38
  sources = generate_repo repo
40
- ::Dust.print_result @node.write("/etc/apt/sources.list.d/#{name}.list", sources, :quiet => true)
39
+ msg.parse_result(@node.write("/etc/apt/sources.list.d/#{name}.list", sources, :quiet => true) )
41
40
  add_repo_key name, repo
42
41
  end
43
42
  end
@@ -48,20 +47,20 @@ class Repositories < Recipe
48
47
  # setting defaults
49
48
  repo['url'] ||= 'http://ftp.debian.org/debian/' if @node.is_debian?
50
49
  repo['url'] ||= 'http://archive.ubuntu.com/ubuntu/' if @node.is_ubuntu?
51
-
50
+
52
51
  repo['release'] ||= @node['lsbdistcodename']
53
52
  repo['components'] ||= 'main'
54
-
53
+
55
54
  # ||= doesn't work for booleans
56
55
  repo['source'] = repo['source'].nil? ? true : repo['source']
57
56
  repo['binary'] = repo['binary'].nil? ? true : repo['binary']
58
- end
59
-
57
+ end
58
+
60
59
  def generate_default_repo repo
61
60
  sources = ''
62
61
  sources << "deb #{repo['url']} #{repo['release']} #{repo['components']}\n"
63
62
  sources << "deb-src #{repo['url']} #{repo['release']} #{repo['components']}\n\n"
64
-
63
+
65
64
  # security
66
65
  if @node.is_debian?
67
66
  sources << "deb http://security.debian.org/ #{repo['release']}/updates #{repo['components']}\n"
@@ -70,17 +69,17 @@ class Repositories < Recipe
70
69
  sources << "deb http://security.ubuntu.com/ubuntu/ #{repo['release']}-security #{repo['components']}\n"
71
70
  sources << "deb-src http://security.ubuntu.com/ubuntu/ #{repo['release']}-security #{repo['components']}\n\n"
72
71
  end
73
-
72
+
74
73
  # updates
75
74
  sources << "deb #{repo['url']} #{repo['release']}-updates #{repo['components']}\n"
76
75
  sources << "deb-src #{repo['url']} #{repo['release']}-updates #{repo['components']}\n\n"
77
-
76
+
78
77
  # proposed
79
78
  if @node.is_ubuntu?
80
79
  sources << "deb #{repo['url']} #{repo['release']}-proposed #{repo['components']}\n"
81
80
  sources << "deb-src #{repo['url']} #{repo['release']}-proposed #{repo['components']}\n\n"
82
81
  end
83
-
82
+
84
83
  # backports is enabled per default in ubuntu oneiric
85
84
  if @node.is_ubuntu?
86
85
  sources << "deb #{repo['url']} #{repo['release']}-backports #{repo['components']}\n"
@@ -89,7 +88,7 @@ class Repositories < Recipe
89
88
 
90
89
  sources
91
90
  end
92
-
91
+
93
92
  def generate_repo repo
94
93
  # add url to sources.list
95
94
  sources = ''
@@ -99,28 +98,27 @@ class Repositories < Recipe
99
98
  end
100
99
  sources
101
100
  end
102
-
101
+
103
102
  def add_repo_key name, repo
104
103
  # add the repository key
105
104
  if repo['key']
106
- ::Dust.print_msg "adding #{name} repository key"
105
+ msg = @node.messages.add("adding #{name} repository key")
107
106
 
108
107
  # if the key is a .deb, download and install it
109
108
  if repo['key'].match /\.deb$/
110
109
  ret = @node.exec 'mktemp --tmpdir dust.XXXXXXXXXX'
111
110
  if ret[:exit_code] != 0
112
- puts
113
- ::Dust.print_failed 'could not create temporary file on server'
111
+ msg.failed('could not create temporary file on server')
114
112
  return false
115
113
  end
116
114
 
117
115
  tmpfile = ret[:stdout].chomp
118
116
 
119
- ::Dust.print_result @node.exec("wget -q -O #{tmpfile} '#{repo['key']}' && dpkg -i #{tmpfile}")[:exit_code]
117
+ msg.parse_result(@node.exec("wget -q -O #{tmpfile} '#{repo['key']}' && dpkg -i #{tmpfile}")[:exit_code])
120
118
 
121
119
  # if not, just download and add the key
122
120
  else
123
- ::Dust.print_result @node.exec("wget -q -O- '#{repo['key']}' |apt-key add -")[:exit_code]
121
+ msg.parse_result(@node.exec("wget -q -O- '#{repo['key']}' |apt-key add -")[:exit_code])
124
122
  end
125
123
  end
126
124
  end
@@ -1,7 +1,7 @@
1
1
  class ResolvConf < Recipe
2
2
  desc 'resolv_conf:deploy', 'configures /etc/resolv.conf'
3
- def deploy
4
- ::Dust.print_msg "configuring resolv.conf\n"
3
+ def deploy
4
+ msg = @node.messages.add("configuring resolv.conf\n")
5
5
 
6
6
  # if config is just true, create empty hash and use defaults
7
7
  @config = {} unless @config.is_a? Hash
@@ -13,37 +13,37 @@ class ResolvConf < Recipe
13
13
 
14
14
  # configures whether daily reports are sent
15
15
  if @config['search']
16
- ::Dust.print_msg "adding search #{@config['search']}", :indent => 2
16
+ msg = @node.messages.add("adding search #{@config['search']}", :indent => 2)
17
17
  config_file << "search #{@config['search']}\n"
18
- ::Dust.print_ok
18
+ msg.ok
19
19
  end
20
20
 
21
21
  if @config['domain']
22
- ::Dust.print_msg "adding domain #{@config['domain']}", :indent => 2
22
+ msg = @node.messages.add("adding domain #{@config['domain']}", :indent => 2)
23
23
  config_file << "domain #{@config['domain']}\n"
24
- ::Dust.print_ok
24
+ msg.ok
25
25
  end
26
26
 
27
27
  if @config['options']
28
- ::Dust.print_msg "adding options #{@config['options']}", :indent => 2
28
+ msg = @node.messages.add("adding options #{@config['options']}", :indent => 2)
29
29
  config_file << "options #{@config['options']}\n"
30
- ::Dust.print_ok
30
+ msg.ok
31
31
  end
32
32
 
33
33
  @config['nameservers'].each do |nameserver|
34
- ::Dust.print_msg "adding nameserver #{nameserver}", :indent => 2
34
+ msg = @node.messages.add("adding nameserver #{nameserver}", :indent => 2)
35
35
  config_file << "nameserver #{nameserver}\n"
36
- ::Dust.print_ok
36
+ msg.ok
37
37
  end
38
-
38
+
39
39
  @node.write '/etc/resolv.conf', config_file
40
40
  end
41
-
41
+
42
42
  desc 'resolv_conf:status', 'shows current /etc/resolv.conf'
43
43
  def status
44
- ::Dust.print_msg 'getting /etc/resolv.conf'
44
+ msg = @node.messages.add('getting /etc/resolv.conf')
45
45
  ret = @node.exec 'cat /etc/resolv.conf'
46
- ::Dust.print_result ret[:exit_code]
47
- ::Dust.print_ret ret
48
- end
46
+ msg.parse_result(ret[:exit_code])
47
+ msg.print_output(ret)
48
+ end
49
49
  end
@@ -2,7 +2,7 @@ class RubyRvm < Recipe
2
2
  desc 'ruby_rvm:deploy', 'installs rvm and ruby for a user'
3
3
  def deploy
4
4
  # TODO: rvm only works if your user uses bash/zsh as login shell, check
5
-
5
+
6
6
  # dependency needed by rvm
7
7
  return unless @node.install_package 'bash'
8
8
  return unless @node.install_package 'curl'
@@ -30,7 +30,7 @@ class RubyRvm < Recipe
30
30
 
31
31
  @config.each do |user, version|
32
32
  unless @node.user_exists? user, :quiet => true
33
- ::Dust.print_warning "user #{user} doesn't exist. skipping"
33
+ @node.messages.add("user #{user} doesn't exist. skipping").warning
34
34
  next
35
35
  end
36
36
 
@@ -41,14 +41,14 @@ class RubyRvm < Recipe
41
41
  return unless set_default user, version
42
42
  end
43
43
  end
44
-
44
+
45
45
  desc 'ruby_rvm:status', 'shows current ruby version'
46
46
  def status
47
47
  @config.each do |user, version|
48
- ::Dust.print_msg "getting current ruby-version for user #{user}"
48
+ msg = @node.messages.add("getting current ruby-version for user #{user}")
49
49
  ret = @node.exec 'rvm use', :as_user => user
50
- ::Dust.print_result ret[:exit_code]
51
- ::Dust.print_ret ret
50
+ msg.parse_result(ret[:exit_code])
51
+ msg.print_output(ret)
52
52
  end
53
53
  end
54
54
 
@@ -58,31 +58,30 @@ class RubyRvm < Recipe
58
58
  def install_rvm user
59
59
  # check if rvm is already installed
60
60
  if @node.exec('which rvm', :as_user => user)[:exit_code] == 0
61
- ::Dust.print_msg "updating rvm for user #{user}"
62
- return ::Dust.print_result @node.exec('rvm get latest', :as_user => user)[:exit_code]
61
+ msg = @node.messages.add("updating rvm for user #{user}")
62
+ return msg.parse_result(@node.exec('rvm get latest', :as_user => user)[:exit_code])
63
63
 
64
64
  else
65
- ::Dust.print_msg "installing rvm for user #{user}"
66
- return ::Dust.print_result @node.exec("curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer |bash -s stable",
67
- :as_user => user)[:exit_code]
65
+ msg = @node.messages.add("installing rvm for user #{user}")
66
+ return msg.parse_result(@node.exec("curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer |bash -s stable", :as_user => user)[:exit_code])
68
67
  end
69
68
  end
70
69
 
71
70
  def install_ruby user, version
72
71
  return true if installed? user, version
73
- ::Dust.print_msg "downloading, compiling and installing ruby-#{version}"
74
- ::Dust.print_result @node.exec("rvm install ruby-#{version}", :as_user => user)[:exit_code]
72
+ msg = @node.messages.add("downloading, compiling and installing ruby-#{version}")
73
+ msg.parse_result( @node.exec("rvm install ruby-#{version}", :as_user => user)[:exit_code])
75
74
  end
76
75
 
77
76
  def set_default user, version
78
- ::Dust.print_msg "setting ruby-#{version} as default"
79
- ::Dust.print_result @node.exec("rvm use ruby-#{version} --default", :as_user => user)[:exit_code]
77
+ msg = @node.messages.add("setting ruby-#{version} as default")
78
+ msg.parse_result(@node.exec("rvm use ruby-#{version} --default", :as_user => user)[:exit_code])
80
79
  end
81
80
 
82
81
  def installed? user, version
83
82
  ret = @node.exec "rvm list |grep ruby-#{version}", :as_user => user
84
83
  if ret[:exit_code] == 0
85
- return ::Dust.print_ok "ruby-#{version} for user #{user} already installed"
84
+ return @node.messages.add("ruby-#{version} for user #{user} already installed").ok
86
85
  end
87
86
  false
88
87
  end
@@ -92,8 +91,8 @@ class RubyRvm < Recipe
92
91
  shell = @node.get_shell user
93
92
  return true if shell == '/bin/zsh' or shell == '/bin/bash'
94
93
 
95
- ::Dust.print_msg "changing shell for #{user} to /bin/bash"
96
- ::Dust.print_result@node.exec("chsh -s /bin/bash #{user}")[:exit_code]
94
+ msg = @node.messages.add("changing shell for #{user} to /bin/bash")
95
+ msg.parse_result(@node.exec("chsh -s /bin/bash #{user}")[:exit_code])
97
96
  end
98
97
 
99
98
  def create_homedir user
@@ -2,12 +2,11 @@ class Skel < Recipe
2
2
  desc 'skel:deploy', 'copy default configuration files to users home directory'
3
3
  def deploy
4
4
  @config.to_array.each do |user|
5
- ::Dust.print_msg "deploying homedir skeleton for #{user}\n"
5
+ @node.messages.add("deploying homedir skeleton for #{user}\n")
6
6
  Dir["#{@template_path}/.*"].each do |file|
7
7
  next unless File.file? file
8
8
  @node.deploy_file file, "/#{@node.get_home user}/#{File.basename file}", { :binding => binding, :indent => 2 }
9
9
  end
10
- puts
11
10
  end
12
11
  end
13
12
  end
@@ -5,10 +5,9 @@ class SshAuthorizedKeys < Recipe
5
5
  def deploy
6
6
 
7
7
  @config.each do |remote_user, ssh_users|
8
- ::Dust.print_msg "generating authorized_keys for #{remote_user}\n"
8
+ @node.messages.add("generating authorized_keys for #{remote_user}\n")
9
9
  authorized_keys = generate_authorized_keys ssh_users
10
10
  deploy_authorized_keys remote_user, authorized_keys
11
- puts
12
11
  end
13
12
  end
14
13
 
@@ -23,14 +22,14 @@ class SshAuthorizedKeys < Recipe
23
22
  # create the authorized_keys hash for this user
24
23
  ssh_users.to_array.each do |ssh_user|
25
24
  users[ssh_user]['name'] ||= ssh_user
26
- ::Dust.print_msg "adding user #{users[ssh_user]['name']}", :indent => 2
25
+ msg = @node.messages.add("adding user #{users[ssh_user]['name']}", :indent => 2)
27
26
  users[ssh_user]['keys'].each do |key|
28
27
  authorized_keys << "#{key}"
29
28
  authorized_keys << " #{users[ssh_user]['name']}" if users[ssh_user]['name']
30
29
  authorized_keys << " <#{users[ssh_user]['email']}>" if users[ssh_user]['email']
31
30
  authorized_keys << "\n"
32
31
  end
33
- ::Dust.print_ok
32
+ msg.ok
34
33
  end
35
34
 
36
35
  authorized_keys
@@ -57,7 +56,7 @@ class SshAuthorizedKeys < Recipe
57
56
  # TODO: add this option
58
57
  def cleanup
59
58
  if options.cleanup?
60
- ::Dust.print_msg "deleting other authorized_keys files\n"
59
+ @node.messages.add("deleting other authorized_keys files\n")
61
60
  @node.get_system_users(:quiet => true).each do |user|
62
61
  next if users.keys.include? user
63
62
  home = @node.get_home user
@@ -81,7 +81,7 @@ class Sshd < Recipe
81
81
  def check_hostkeys
82
82
  @config['HostKey'].each do |hostkey|
83
83
  unless @node.file_exists? hostkey, :quiet => true
84
- ::Dust.print_warning "hostkey '#{hostkey}' not found. removing from config"
84
+ @node.messages.add("hostkey '#{hostkey}' not found. removing from config").warning
85
85
  @config['HostKey'].delete hostkey
86
86
  end
87
87
  end
@@ -6,7 +6,7 @@ class Sudoers < Recipe
6
6
  remove_rules
7
7
 
8
8
  @config.each do |name, rule|
9
- ::Dust.print_msg "deploying sudo rules '#{name}'\n"
9
+ @node.messages.add("deploying sudo rules '#{name}'\n")
10
10
 
11
11
  # rulename: 'myrule'
12
12
  if rule.is_a? String
@@ -15,7 +15,7 @@ class Sudoers < Recipe
15
15
  # rulename: { user: [ user1, user2 ], command: [ cmd1, cmd2 ] }
16
16
  else
17
17
  unless rule['user'] and rule['command']
18
- ::Dust.print_failed 'user or command missing', :indent => 2
18
+ @node.messages.add('user or command missing', :indent => 2).failed
19
19
  next
20
20
  end
21
21
 
@@ -3,7 +3,7 @@ class Sysctl < Recipe
3
3
  def deploy
4
4
  # we need support for /etc/sysctl.d/
5
5
  unless @node.dir_exists? '/etc/sysctl.d/'
6
- return ::Dust.print_warning 'sysctl configuration not supported for your linux distribution'
6
+ return @node.messages.add('sysctl configuration not supported for your linux distribution').warning
7
7
  end
8
8
 
9
9
  # seperate templates from sysctls
@@ -13,14 +13,13 @@ class Sysctl < Recipe
13
13
  # apply template sysctls
14
14
  if templates
15
15
  templates.to_array.each do |template|
16
- ::Dust.print_msg "configuring sysctls for template #{template}\n"
16
+ @node.messages.add("configuring sysctls for template #{template}\n")
17
17
  apply template, self.send(template)
18
- puts
19
18
  end
20
19
  end
21
20
 
22
21
  # apply plain sysctls
23
- ::Dust.print_msg "configuring plain sysctls\n"
22
+ @node.messages.add("configuring plain sysctls\n")
24
23
  apply 'dust', sysctls
25
24
  end
26
25
 
@@ -30,13 +29,13 @@ class Sysctl < Recipe
30
29
  def apply name, sysctl
31
30
  sysctl_conf = ''
32
31
  sysctl.each do |key, value|
33
- ::Dust.print_msg "setting #{key} = #{value}", :indent => 2
34
- ::Dust.print_result @node.exec("sysctl -w #{key}=#{value}")[:exit_code]
32
+ msg = @node.messages.add("setting #{key} = #{value}", :indent => 2)
33
+ msg.parse_result(@node.exec("sysctl -w #{key}=#{value}")[:exit_code])
35
34
  sysctl_conf << "#{key} = #{value}\n"
36
35
  end
37
36
 
38
- ::Dust.print_msg "saving settings to /etc/sysctl.d/10-#{name}.conf", :indent => 2
39
- ::Dust.print_result @node.write("/etc/sysctl.d/10-#{name}.conf", sysctl_conf, :quiet => true)
37
+ msg = @node.messages.add("saving settings to /etc/sysctl.d/10-#{name}.conf", :indent => 2)
38
+ msg.parse_result(@node.write("/etc/sysctl.d/10-#{name}.conf", sysctl_conf, :quiet => true))
40
39
  end
41
40
 
42
41
 
@@ -47,6 +46,11 @@ class Sysctl < Recipe
47
46
  database.merge 'vm.overcommit_memory' => 2
48
47
  end
49
48
 
49
+ # redis complains if vm.overcommit_memory != 1
50
+ def redis
51
+ { 'vm.overcommit_memory' => 1, 'vm.swappiness' => 0 }
52
+ end
53
+
50
54
  def mysql
51
55
  database
52
56
  end