dust-deploy 0.3.3 → 0.4.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.
Files changed (36) hide show
  1. data/bin/dust +7 -7
  2. data/changelog.md +9 -0
  3. data/lib/dust.rb +1 -0
  4. data/lib/dust/examples/nodes/db-staging.yaml +9 -10
  5. data/lib/dust/examples/nodes/mail.yaml +2 -1
  6. data/lib/dust/examples/nodes/mysql-production.yaml +4 -1
  7. data/lib/dust/examples/nodes/proxy-staging.yaml +4 -12
  8. data/lib/dust/examples/templates/motd/motd.erb +2 -2
  9. data/lib/dust/examples/templates/postgres/pacemaker.sh.erb +6 -6
  10. data/lib/dust/examples/templates/postgres/postgresql.conf.erb +8 -8
  11. data/lib/dust/examples/templates/postgres/recovery.conf.erb +4 -4
  12. data/lib/dust/examples/templates/zabbix_agent/zabbix_agentd.conf.erb +13 -13
  13. data/lib/dust/recipe.rb +15 -0
  14. data/lib/dust/recipes/aliases.rb +5 -7
  15. data/lib/dust/recipes/basic_setup.rb +13 -15
  16. data/lib/dust/recipes/debsecan.rb +7 -7
  17. data/lib/dust/recipes/duplicity.rb +22 -27
  18. data/lib/dust/recipes/etc_hosts.rb +6 -8
  19. data/lib/dust/recipes/iptables.rb +6 -11
  20. data/lib/dust/recipes/locale.rb +8 -8
  21. data/lib/dust/recipes/memory_limit.rb +6 -8
  22. data/lib/dust/recipes/motd.rb +4 -6
  23. data/lib/dust/recipes/mysql.rb +20 -22
  24. data/lib/dust/recipes/newrelic.rb +8 -8
  25. data/lib/dust/recipes/nginx.rb +12 -14
  26. data/lib/dust/recipes/packages.rb +4 -4
  27. data/lib/dust/recipes/postgres.rb +53 -61
  28. data/lib/dust/recipes/rc_local.rb +7 -7
  29. data/lib/dust/recipes/remove_packages.rb +4 -4
  30. data/lib/dust/recipes/repositories.rb +18 -18
  31. data/lib/dust/recipes/resolv_conf.rb +15 -15
  32. data/lib/dust/recipes/ssh_authorized_keys.rb +12 -14
  33. data/lib/dust/recipes/unattended_upgrades.rb +16 -18
  34. data/lib/dust/recipes/zabbix_agent.rb +29 -31
  35. data/lib/dust/version.rb +1 -1
  36. metadata +4 -3
@@ -1,21 +1,21 @@
1
- class RcLocal < Thor
1
+ class RcLocal < Recipe
2
2
  desc 'rc_local:deploy', 'configures custom startup script'
3
- def deploy node, config, options
3
+ def deploy
4
4
 
5
- if node.uses_apt?
5
+ if @node.uses_apt?
6
6
  ::Dust.print_msg "configuring custom startup script\n"
7
7
 
8
8
  rc = ''
9
- config.each do |cmd|
9
+ @config.each do |cmd|
10
10
  ::Dust.print_msg "adding command: #{cmd}", :indent => 2
11
11
  rc += "#{cmd}\n"
12
12
  ::Dust.print_ok
13
13
  end
14
14
  rc += "\nexit 0\n"
15
15
 
16
- node.write '/etc/rc.local', rc
17
- node.chown 'root:root', '/etc/rc.local'
18
- node.chmod '755', '/etc/rc.local'
16
+ @node.write '/etc/rc.local', rc
17
+ @node.chown 'root:root', '/etc/rc.local'
18
+ @node.chmod '755', '/etc/rc.local'
19
19
  else
20
20
  ::Dust.print_failed 'os not supported'
21
21
  end
@@ -1,8 +1,8 @@
1
- class RemovePackages < Thor
1
+ class RemovePackages < Recipe
2
2
  desc 'remove_packages:deploy', 'removes packages'
3
- def deploy node, packages, options
4
- packages.each do |package|
5
- node.remove_package package
3
+ def deploy
4
+ @config.each do |package|
5
+ @node.remove_package package
6
6
  end
7
7
  end
8
8
  end
@@ -1,24 +1,24 @@
1
- class Repositories < Thor
1
+ class Repositories < Recipe
2
2
  desc 'repositories:deploy', 'configures package management repositories (aptitude, yum)'
3
- def deploy node, repos, options
4
- node.collect_facts
3
+ def deploy
4
+ @node.collect_facts
5
5
 
6
- if node.uses_apt? :quiet=>false
6
+ if @node.uses_apt? :quiet=>false
7
7
  :: Dust.print_msg 'deleting old repositories'
8
- node.rm '/etc/apt/sources.list.d/*.list', :quiet => true
8
+ @node.rm '/etc/apt/sources.list.d/*.list', :quiet => true
9
9
  ::Dust.print_ok
10
10
 
11
11
  puts
12
- repos.each do |name, repo|
12
+ @config.each do |name, repo|
13
13
 
14
14
  # if repo is present but not a hash use defaults
15
15
  repo = {} unless repo.is_a? Hash
16
16
 
17
17
  # setting defaults
18
- repo['url'] ||= 'http://ftp.debian.org/debian/' if node.is_debian?
19
- repo['url'] ||= 'http://archive.ubuntu.com/ubuntu/' if node.is_ubuntu?
18
+ repo['url'] ||= 'http://ftp.debian.org/debian/' if @node.is_debian?
19
+ repo['url'] ||= 'http://archive.ubuntu.com/ubuntu/' if @node.is_ubuntu?
20
20
 
21
- repo['release'] ||= node['lsbdistcodename']
21
+ repo['release'] ||= @node['lsbdistcodename']
22
22
  repo['components'] ||= 'main'
23
23
 
24
24
  # ||= doesn't work for booleans
@@ -34,10 +34,10 @@ class Repositories < Thor
34
34
  "deb-src #{repo['url']} #{repo['release']} #{repo['components']}\n\n"
35
35
 
36
36
  # security
37
- if node.is_debian?
37
+ if @node.is_debian?
38
38
  sources += "deb http://security.debian.org/ #{repo['release']}/updates #{repo['components']}\n" +
39
39
  "deb-src http://security.debian.org/ #{repo['release']}/updates #{repo['components']}\n\n"
40
- elsif node.is_ubuntu?
40
+ elsif @node.is_ubuntu?
41
41
  sources += "deb http://security.ubuntu.com/ubuntu/ #{repo['release']}-security #{repo['components']}\n" +
42
42
  "deb-src http://security.ubuntu.com/ubuntu/ #{repo['release']}-security #{repo['components']}\n\n"
43
43
  end
@@ -47,18 +47,18 @@ class Repositories < Thor
47
47
  "deb-src #{repo['url']} #{repo['release']}-updates #{repo['components']}\n\n"
48
48
 
49
49
  # proposed
50
- if node.is_ubuntu?
50
+ if @node.is_ubuntu?
51
51
  sources += "deb #{repo['url']} #{repo['release']}-proposed #{repo['components']}\n" +
52
52
  "deb-src #{repo['url']} #{repo['release']}-proposed #{repo['components']}\n\n"
53
53
  end
54
54
 
55
55
  # backports is enabled per default in ubuntu oneiric
56
- if node.is_ubuntu?
56
+ if @node.is_ubuntu?
57
57
  sources += "deb #{repo['url']} #{repo['release']}-backports #{repo['components']}\n" +
58
58
  "deb-src #{repo['url']} #{repo['release']}-backports #{repo['components']}\n\n"
59
59
  end
60
60
 
61
- ::Dust.print_result node.write('/etc/apt/sources.list', sources, :quiet => true)
61
+ ::Dust.print_result @node.write('/etc/apt/sources.list', sources, :quiet => true)
62
62
 
63
63
  else
64
64
  # add url to sources.list
@@ -67,17 +67,17 @@ class Repositories < Thor
67
67
  sources += "deb-src #{repo['url']} #{repo['release']} #{repo['components']}\n" if repo['source']
68
68
 
69
69
  ::Dust.print_msg "adding repository '#{name}' to sources"
70
- ::Dust.print_result node.write("/etc/apt/sources.list.d/#{name}.list", sources, :quiet => true)
70
+ ::Dust.print_result @node.write("/etc/apt/sources.list.d/#{name}.list", sources, :quiet => true)
71
71
 
72
72
  # add the repository key
73
73
  if repo['key']
74
74
  ::Dust.print_msg "adding #{name} repository key"
75
- ::Dust.print_result node.exec("wget -O- '#{repo['key']}' | apt-key add -")[:exit_code]
75
+ ::Dust.print_result @node.exec("wget -O- '#{repo['key']}' | apt-key add -")[:exit_code]
76
76
  end
77
77
  end
78
78
  end
79
79
 
80
- elsif node.uses_rpm? :quiet=>false
80
+ elsif @node.uses_rpm? :quiet=>false
81
81
  ::Dust.print_failed 'rpm not yet supported'
82
82
 
83
83
  else
@@ -86,7 +86,7 @@ class Repositories < Thor
86
86
 
87
87
  # fetch new stuff
88
88
  puts
89
- node.update_repos if options.restart? or options.reload?
89
+ @node.update_repos if options.restart? or options.reload?
90
90
  end
91
91
  end
92
92
 
@@ -1,42 +1,42 @@
1
- class ResolvConf < Thor
1
+ class ResolvConf < Recipe
2
2
  desc 'resolv_conf:deploy', 'configures /etc/resolv.conf'
3
- def deploy node, config, options
3
+ def deploy
4
4
  ::Dust.print_msg "configuring resolv.conf\n"
5
5
 
6
6
  # if config is just true, create empty hash and use defaults
7
- config = {} unless config.is_a? Hash
7
+ @config = {} unless @config.is_a? Hash
8
8
 
9
9
  # setting default config variables (unless already set)
10
- config['nameservers'] ||= [ '208.67.222.222', '208.67.220.220' ] # opendns
10
+ @config['nameservers'] ||= [ '208.67.222.222', '208.67.220.220' ] # opendns
11
11
 
12
12
  config_file = ''
13
13
 
14
14
  # configures whether daily reports are sent
15
- if config['search']
16
- ::Dust.print_msg "adding search #{config['search']}", :indent => 2
17
- config_file += "search #{config['search']}\n"
15
+ if @config['search']
16
+ ::Dust.print_msg "adding search #{@config['search']}", :indent => 2
17
+ config_file += "search #{@config['search']}\n"
18
18
  ::Dust.print_ok
19
19
  end
20
20
 
21
- if config['domain']
22
- ::Dust.print_msg "adding domain #{config['domain']}", :indent => 2
23
- config_file += "domain #{config['domain']}\n"
21
+ if @config['domain']
22
+ ::Dust.print_msg "adding domain #{@config['domain']}", :indent => 2
23
+ config_file += "domain #{@config['domain']}\n"
24
24
  ::Dust.print_ok
25
25
  end
26
26
 
27
- if config['options']
28
- ::Dust.print_msg "adding options #{config['options']}", :indent => 2
29
- config_file += "options #{config['options']}\n"
27
+ if @config['options']
28
+ ::Dust.print_msg "adding options #{@config['options']}", :indent => 2
29
+ config_file += "options #{@config['options']}\n"
30
30
  ::Dust.print_ok
31
31
  end
32
32
 
33
- config['nameservers'].each do |nameserver|
33
+ @config['nameservers'].each do |nameserver|
34
34
  ::Dust.print_msg "adding nameserver #{nameserver}", :indent => 2
35
35
  config_file += "nameserver #{nameserver}\n"
36
36
  ::Dust.print_ok
37
37
  end
38
38
 
39
- node.write '/etc/resolv.conf', config_file
39
+ @node.write '/etc/resolv.conf', config_file
40
40
  end
41
41
  end
42
42
 
@@ -1,15 +1,13 @@
1
1
  require 'yaml'
2
2
 
3
- class SshAuthorizedKeys < Thor
3
+ class SshAuthorizedKeys < Recipe
4
4
  desc 'ssh_authorized_keys:deploy', 'configures ssh authorized_keys'
5
- def deploy node, ingredients, options
6
- template_path = "./templates/#{ File.basename(__FILE__).chomp( File.extname(__FILE__) ) }"
7
-
5
+ def deploy
8
6
  # load users and their ssh keys from yaml file
9
- users = YAML.load_file "#{template_path}/users.yaml"
7
+ users = YAML.load_file "#{@template_path}/users.yaml"
10
8
 
11
9
  authorized_keys = {}
12
- ingredients.each do |remote_user, ssh_users|
10
+ @config.each do |remote_user, ssh_users|
13
11
  ::Dust.print_msg "generating authorized_keys for #{remote_user}\n"
14
12
  authorized_keys = ''
15
13
 
@@ -28,27 +26,27 @@ class SshAuthorizedKeys < Thor
28
26
  end
29
27
 
30
28
  # create user, if not existent
31
- next unless node.create_user remote_user
29
+ next unless @node.create_user remote_user
32
30
 
33
31
  # check and create necessary directories
34
- next unless node.mkdir("~#{remote_user}/.ssh")
32
+ next unless @node.mkdir("~#{remote_user}/.ssh")
35
33
 
36
34
  # deploy authorized_keys
37
- next unless node.write "~#{remote_user}/.ssh/authorized_keys", authorized_keys
35
+ next unless @node.write "~#{remote_user}/.ssh/authorized_keys", authorized_keys
38
36
 
39
37
  # check permissions
40
- node.chown "#{remote_user}:#{remote_user}", "~#{remote_user}/.ssh"
41
- node.chmod '0644', "~#{remote_user}/.ssh/authorized_keys"
38
+ @node.chown "#{remote_user}:#{remote_user}", "~#{remote_user}/.ssh"
39
+ @node.chmod '0644', "~#{remote_user}/.ssh/authorized_keys"
42
40
 
43
41
 
44
42
  # TODO: add this option
45
43
  # remove authorized_keys files for all other users
46
44
  if options.cleanup?
47
45
  ::Dust.print_msg "deleting other authorized_keys files\n"
48
- node.get_system_users(:quiet => true).each do |user|
46
+ @node.get_system_users(:quiet => true).each do |user|
49
47
  next if users.keys.include? user
50
- if node.file_exists? "~#{user}/.ssh/authorized_keys", :quiet => true
51
- node.rm "~#{user}/.ssh/authorized_keys", :indent => 2
48
+ if @node.file_exists? "~#{user}/.ssh/authorized_keys", :quiet => true
49
+ @node.rm "~#{user}/.ssh/authorized_keys", :indent => 2
52
50
  end
53
51
  end
54
52
  end
@@ -1,29 +1,27 @@
1
- class UnattendedUpgrades < Thor
1
+ class UnattendedUpgrades < Recipe
2
2
  desc 'unattended_upgrades:deploy', 'installs and configures automatic system updates for debian and ubuntu'
3
- def deploy node, config, options
4
- template_path = "./templates/#{ File.basename(__FILE__).chomp( File.extname(__FILE__) ) }"
3
+ def deploy
4
+ return unless @node.uses_apt?
5
+ @node.install_package 'unattended-upgrades'
5
6
 
6
- return unless node.uses_apt?
7
- node.install_package 'unattended-upgrades'
8
-
9
- config = {} unless config.is_a? Hash
7
+ @config = {} unless @config.is_a? Hash
10
8
 
11
9
  # set defaults for non-set config
12
- config['enable'] ||= 1
13
- config['update-package-lists'] ||= 1
14
- config['unattended-upgrade'] ||= 1
15
- config['autocleaninterval'] ||= 1
16
- config['verbose'] ||= 0
10
+ @config['enable'] ||= 1
11
+ @config['update-package-lists'] ||= 1
12
+ @config['unattended-upgrade'] ||= 1
13
+ @config['autocleaninterval'] ||= 1
14
+ @config['verbose'] ||= 0
17
15
 
18
16
  # generate configuration file
19
17
  periodic = ''
20
- periodic += "APT::Periodic::Enable \"#{config['enable']}\";\n"
21
- periodic += "APT::Periodic::Update-Package-Lists \"#{config['update-package-lists']}\";\n"
22
- periodic += "APT::Periodic::Unattended-Upgrade \"#{config['unattended-upgrade']}\";\n"
23
- periodic += "APT::Periodic::AutocleanInterval \"#{config['autocleaninterval']}\";\n"
24
- periodic += "APT::Periodic::Verbose \"#{config['verbose']}\";\n"
18
+ periodic += "APT::Periodic::Enable \"#{@config['enable']}\";\n"
19
+ periodic += "APT::Periodic::Update-Package-Lists \"#{@config['update-package-lists']}\";\n"
20
+ periodic += "APT::Periodic::Unattended-Upgrade \"#{@config['unattended-upgrade']}\";\n"
21
+ periodic += "APT::Periodic::AutocleanInterval \"#{@config['autocleaninterval']}\";\n"
22
+ periodic += "APT::Periodic::Verbose \"#{@config['verbose']}\";\n"
25
23
 
26
- node.write '/etc/apt/apt.conf.d/02periodic', periodic
24
+ @node.write '/etc/apt/apt.conf.d/02periodic', periodic
27
25
  end
28
26
  end
29
27
 
@@ -1,46 +1,44 @@
1
1
  require 'erb'
2
2
 
3
- class ZabbixAgent < Thor
3
+ class ZabbixAgent < Recipe
4
4
  desc 'zabbix_agent:deploy', 'installs and configures zabbix agent'
5
- def deploy node, ingredients, options
6
- template_path = "./templates/#{ File.basename(__FILE__).chomp( File.extname(__FILE__) ) }"
5
+ def deploy
6
+ return unless install_zabbix
7
7
 
8
- return unless install_zabbix node
9
-
10
- # configure node using erb template
11
- template = ERB.new File.read("#{template_path}/zabbix_agentd.conf.erb"), nil, '%<>'
8
+ # configure @node using erb template
9
+ template = ERB.new File.read("#{@template_path}/zabbix_agentd.conf.erb"), nil, '%<>'
12
10
  ::Dust.print_msg 'adjusting and deploying zabbix_agentd.conf'
13
- node.write '/etc/zabbix/zabbix_agentd.conf', template.result(binding), :quiet => true
11
+ @node.write '/etc/zabbix/zabbix_agentd.conf', template.result(binding), :quiet => true
14
12
  ::Dust.print_ok
15
13
 
16
14
  # restart using new configuration
17
- if node.uses_emerge? :quiet => true
18
- node.autostart_service 'zabbix-agentd'
19
- node.restart_service 'zabbix-agentd' if options.restart?
15
+ if @node.uses_emerge? :quiet => true
16
+ @node.autostart_service 'zabbix-agentd'
17
+ @node.restart_service 'zabbix-agentd' if options.restart?
20
18
  else
21
- node.autostart_service 'zabbix-agent'
22
- node.restart_service 'zabbix-agent' if options.restart?
19
+ @node.autostart_service 'zabbix-agent'
20
+ @node.restart_service 'zabbix-agent' if options.restart?
23
21
  end
24
22
  end
25
23
 
26
24
  private
27
25
  # installs zabbix and its dependencies
28
- def install_zabbix node
26
+ def install_zabbix
29
27
 
30
- if node.uses_apt?
31
- return false unless node.install_package 'zabbix-agent'
28
+ if @node.uses_apt?
29
+ return false unless @node.install_package 'zabbix-agent'
32
30
 
33
31
  # debsecan is needed for zabbix checks (security updates)
34
- return false unless node.install_package 'debsecan'
32
+ return false unless @node.install_package 'debsecan'
35
33
 
36
- elsif node.uses_emerge?
37
- return false unless node.install_package 'zabbix', :env => 'USE=agent'
34
+ elsif @node.uses_emerge?
35
+ return false unless @node.install_package 'zabbix', :env => 'USE=agent'
38
36
 
39
37
  # glsa-check (part of gentoolkit) is needed for zabbix checks (security updates)
40
- return false unless node.install_package 'gentoolkit'
38
+ return false unless @node.install_package 'gentoolkit'
41
39
 
42
- elsif node.uses_rpm?
43
- return false unless node.install_package 'zabbix-agent'
40
+ elsif @node.uses_rpm?
41
+ return false unless @node.install_package 'zabbix-agent'
44
42
 
45
43
  else
46
44
  ::Dust.print_msg 'os not supported'
@@ -53,32 +51,32 @@ class ZabbixAgent < Thor
53
51
 
54
52
  # TODO (not yet finished)
55
53
  desc 'zabbix_agent:postgres', 'configure postgres database for zabbix monitoring'
56
- def postgres node, ingredients, options
57
- next unless node.uses_emerge? :quiet=>false
58
- next unless node.package_installed?('postgresql-node')
54
+ def postgres
55
+ next unless @node.uses_emerge? :quiet=>false
56
+ next unless @node.package_installed?('postgresql-@node')
59
57
 
60
58
  ::Dust.print_msg 'add zabbix system user to postgres group'
61
- ::Dust.print_result( node.exec('usermod -a -G postgres zabbix')[:exit_code] )
59
+ ::Dust.print_result( @node.exec('usermod -a -G postgres zabbix')[:exit_code] )
62
60
 
63
61
  ::Dust.print_msg 'checking if zabbix user exists in postgres'
64
- ret = ::Dust.print_result( node.exec('psql -U postgres -c ' +
62
+ ret = ::Dust.print_result( @node.exec('psql -U postgres -c ' +
65
63
  ' "SELECT usename FROM pg_user WHERE usename = \'zabbix\'"' +
66
64
  ' postgres |grep -q zabbix')[:exit_code] )
67
65
 
68
66
  # if user was not found, create him
69
67
  unless ret
70
68
  ::Dust.print_msg 'create zabbix user in postgres', :indent => 2
71
- ::Dust.print_result( node.exec('createuser -U postgres zabbix -RSD')[:exit_code] )
69
+ ::Dust.print_result( @node.exec('createuser -U postgres zabbix -RSD')[:exit_code] )
72
70
  end
73
71
 
74
72
  # TODO: only GRANT is this is a master
75
73
  ::Dust.print_msg 'GRANT zabbix user access to postgres database'
76
- ::Dust.print_result( node.exec('psql -U postgres -c "GRANT SELECT ON pg_stat_database TO zabbix" postgres')[:exit_code] )
74
+ ::Dust.print_result( @node.exec('psql -U postgres -c "GRANT SELECT ON pg_stat_database TO zabbix" postgres')[:exit_code] )
77
75
 
78
76
  # reload postgresql
79
- node.reload_service('postgresql-9.0')
77
+ @node.reload_service('postgresql-9.0')
80
78
 
81
- node.disconnect
79
+ @node.disconnect
82
80
  puts
83
81
  end
84
82
  end
data/lib/dust/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dust
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- - 3
9
- version: 0.3.3
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - kris kechagia
@@ -124,6 +124,7 @@ files:
124
124
  - lib/dust/examples/templates/zabbix_agent/zabbix_agentd.conf.erb
125
125
  - lib/dust/helper.rb
126
126
  - lib/dust/print_status.rb
127
+ - lib/dust/recipe.rb
127
128
  - lib/dust/recipes/aliases.rb
128
129
  - lib/dust/recipes/basic_setup.rb
129
130
  - lib/dust/recipes/debsecan.rb