vagabond 0.2.8 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. data/CHANGELOG.md +16 -0
  2. data/DEVELOP.md +38 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +33 -0
  5. data/README.md +55 -21
  6. data/USAGE.md +28 -3
  7. data/Vagabondfile.sample +47 -0
  8. data/Vagrantfile +17 -5
  9. data/bin/vagabond +5 -0
  10. data/lib/vagabond/Cheffile +7 -0
  11. data/lib/vagabond/Cheffile.dev +7 -0
  12. data/lib/vagabond/actions/cluster.rb +22 -8
  13. data/lib/vagabond/actions/create.rb +7 -4
  14. data/lib/vagabond/actions/destroy.rb +24 -14
  15. data/lib/vagabond/actions/freeze.rb +1 -0
  16. data/lib/vagabond/actions/init.rb +8 -11
  17. data/lib/vagabond/actions/provision.rb +16 -8
  18. data/lib/vagabond/actions/rebuild.rb +4 -9
  19. data/lib/vagabond/actions/ssh.rb +9 -1
  20. data/lib/vagabond/actions/start.rb +1 -0
  21. data/lib/vagabond/actions/status.rb +1 -0
  22. data/lib/vagabond/actions/thaw.rb +1 -0
  23. data/lib/vagabond/actions/up.rb +22 -7
  24. data/lib/vagabond/bootstraps/chef_10_compat_config.erb +62 -0
  25. data/lib/vagabond/bootstraps/no_lazy_load.erb +63 -0
  26. data/lib/vagabond/bootstraps/server-zero.erb +1 -8
  27. data/lib/vagabond/bootstraps/server.erb +9 -6
  28. data/lib/vagabond/constants.rb +1 -6
  29. data/lib/vagabond/core.rb +209 -0
  30. data/lib/vagabond/errors.rb +3 -0
  31. data/lib/vagabond/helpers.rb +11 -99
  32. data/lib/vagabond/helpers/base.rb +134 -0
  33. data/lib/vagabond/helpers/callbacks.rb +47 -0
  34. data/lib/vagabond/helpers/chains.rb +23 -0
  35. data/lib/vagabond/helpers/commands.rb +49 -0
  36. data/lib/vagabond/helpers/knife.rb +47 -0
  37. data/lib/vagabond/helpers/naming.rb +39 -0
  38. data/lib/vagabond/helpers/server.rb +30 -0
  39. data/lib/vagabond/internal_configuration.rb +186 -32
  40. data/lib/vagabond/kitchen.rb +110 -60
  41. data/lib/vagabond/knife.rb +5 -1
  42. data/lib/vagabond/layout.rb +1 -0
  43. data/lib/vagabond/monkey/kitchen_config.rb +1 -0
  44. data/lib/vagabond/notify_mash.rb +25 -0
  45. data/lib/vagabond/server.rb +81 -49
  46. data/lib/vagabond/settings.rb +17 -0
  47. data/lib/vagabond/spec.rb +125 -99
  48. data/lib/vagabond/uploader.rb +4 -1
  49. data/lib/vagabond/uploader/berkshelf.rb +2 -1
  50. data/lib/vagabond/uploader/knife.rb +3 -9
  51. data/lib/vagabond/uploader/librarian.rb +2 -5
  52. data/lib/vagabond/vagabond.rb +77 -93
  53. data/lib/vagabond/vagabondfile.rb +73 -9
  54. data/lib/vagabond/version.rb +2 -1
  55. data/vagabond.gemspec +7 -5
  56. metadata +58 -81
  57. data/lib/vagabond/cookbooks/apt/Berksfile +0 -8
  58. data/lib/vagabond/cookbooks/apt/CHANGELOG.md +0 -97
  59. data/lib/vagabond/cookbooks/apt/CONTRIBUTING +0 -29
  60. data/lib/vagabond/cookbooks/apt/LICENSE +0 -201
  61. data/lib/vagabond/cookbooks/apt/README.md +0 -243
  62. data/lib/vagabond/cookbooks/apt/TESTING.md +0 -25
  63. data/lib/vagabond/cookbooks/apt/attributes/default.rb +0 -4
  64. data/lib/vagabond/cookbooks/apt/files/default/apt-proxy-v2.conf +0 -50
  65. data/lib/vagabond/cookbooks/apt/metadata.rb +0 -30
  66. data/lib/vagabond/cookbooks/apt/providers/preference.rb +0 -61
  67. data/lib/vagabond/cookbooks/apt/providers/repository.rb +0 -132
  68. data/lib/vagabond/cookbooks/apt/recipes/cacher-client.rb +0 -59
  69. data/lib/vagabond/cookbooks/apt/recipes/cacher-ng.rb +0 -40
  70. data/lib/vagabond/cookbooks/apt/recipes/default.rb +0 -68
  71. data/lib/vagabond/cookbooks/apt/resources/preference.rb +0 -30
  72. data/lib/vagabond/cookbooks/apt/resources/repository.rb +0 -40
  73. data/lib/vagabond/cookbooks/apt/templates/debian-6.0/acng.conf.erb +0 -174
  74. data/lib/vagabond/cookbooks/apt/templates/default/01proxy.erb +0 -2
  75. data/lib/vagabond/cookbooks/apt/templates/default/acng.conf.erb +0 -276
  76. data/lib/vagabond/cookbooks/apt/templates/ubuntu-10.04/acng.conf.erb +0 -270
  77. data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/README.md +0 -1
  78. data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/files/default/tests/minitest/cacher-ng_test.rb +0 -28
  79. data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/files/default/tests/minitest/default_test.rb +0 -28
  80. data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/files/default/tests/minitest/lwrps_test.rb +0 -48
  81. data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/files/default/tests/minitest/support/helpers.rb +0 -29
  82. data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/metadata.rb +0 -6
  83. data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/recipes/cacher-ng.rb +0 -20
  84. data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/recipes/default.rb +0 -20
  85. data/lib/vagabond/cookbooks/apt/test/cookbooks/apt_test/recipes/lwrps.rb +0 -66
  86. data/lib/vagabond/cookbooks/lxc/CHANGELOG.md +0 -37
  87. data/lib/vagabond/cookbooks/lxc/Gemfile +0 -4
  88. data/lib/vagabond/cookbooks/lxc/Gemfile.lock +0 -41
  89. data/lib/vagabond/cookbooks/lxc/README.md +0 -112
  90. data/lib/vagabond/cookbooks/lxc/attributes/default.rb +0 -26
  91. data/lib/vagabond/cookbooks/lxc/files/default/knife_lxc +0 -228
  92. data/lib/vagabond/cookbooks/lxc/files/default/lxc-awesome-ephemeral +0 -499
  93. data/lib/vagabond/cookbooks/lxc/libraries/lxc.rb +0 -477
  94. data/lib/vagabond/cookbooks/lxc/libraries/lxc_expanded_resources.rb +0 -40
  95. data/lib/vagabond/cookbooks/lxc/libraries/lxc_file_config.rb +0 -84
  96. data/lib/vagabond/cookbooks/lxc/libraries/monkey.rb +0 -51
  97. data/lib/vagabond/cookbooks/lxc/metadata.rb +0 -12
  98. data/lib/vagabond/cookbooks/lxc/providers/config.rb +0 -75
  99. data/lib/vagabond/cookbooks/lxc/providers/container.rb +0 -354
  100. data/lib/vagabond/cookbooks/lxc/providers/default.rb +0 -57
  101. data/lib/vagabond/cookbooks/lxc/providers/ephemeral.rb +0 -40
  102. data/lib/vagabond/cookbooks/lxc/providers/fstab.rb +0 -30
  103. data/lib/vagabond/cookbooks/lxc/providers/interface.rb +0 -45
  104. data/lib/vagabond/cookbooks/lxc/providers/service.rb +0 -53
  105. data/lib/vagabond/cookbooks/lxc/recipes/containers.rb +0 -13
  106. data/lib/vagabond/cookbooks/lxc/recipes/default.rb +0 -58
  107. data/lib/vagabond/cookbooks/lxc/recipes/install_dependencies.rb +0 -15
  108. data/lib/vagabond/cookbooks/lxc/recipes/knife.rb +0 -37
  109. data/lib/vagabond/cookbooks/lxc/resources/config.rb +0 -19
  110. data/lib/vagabond/cookbooks/lxc/resources/container.rb +0 -54
  111. data/lib/vagabond/cookbooks/lxc/resources/default.rb +0 -12
  112. data/lib/vagabond/cookbooks/lxc/resources/ephemeral.rb +0 -13
  113. data/lib/vagabond/cookbooks/lxc/resources/fstab.rb +0 -12
  114. data/lib/vagabond/cookbooks/lxc/resources/interface.rb +0 -13
  115. data/lib/vagabond/cookbooks/lxc/resources/service.rb +0 -5
  116. data/lib/vagabond/cookbooks/lxc/templates/default/client.rb.erb +0 -13
  117. data/lib/vagabond/cookbooks/lxc/templates/default/default-lxc.erb +0 -3
  118. data/lib/vagabond/cookbooks/lxc/templates/default/file_content.erb +0 -2
  119. data/lib/vagabond/cookbooks/lxc/templates/default/fstab.erb +0 -5
  120. data/lib/vagabond/cookbooks/lxc/templates/default/interface.erb +0 -27
  121. data/lib/vagabond/cookbooks/vagabond/README.md +0 -10
  122. data/lib/vagabond/cookbooks/vagabond/attributes/default.rb +0 -18
  123. data/lib/vagabond/cookbooks/vagabond/files/default/lxc-centos +0 -460
  124. data/lib/vagabond/cookbooks/vagabond/libraries/vagabond.rb +0 -10
  125. data/lib/vagabond/cookbooks/vagabond/metadata.rb +0 -8
  126. data/lib/vagabond/cookbooks/vagabond/recipes/default.rb +0 -132
  127. data/lib/vagabond/cookbooks/vagabond/recipes/zero.rb +0 -9
  128. data/lib/vagabond/helpers/cheffile_loader.rb +0 -20
  129. data/vagabond-0.2.6.gem +0 -0
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  require 'elecksee/ephemeral'
2
3
 
3
4
  module Vagabond
@@ -6,13 +7,14 @@ module Vagabond
6
7
  def _create
7
8
  name_required!
8
9
  if(lxc.exists?)
9
- ui.warn "Node already exists: #{name}" unless name == 'server'
10
- _start
10
+ ui.warn "Node already exists: #{name}"
11
+ add_link(:start)
11
12
  else
12
13
  ui.info "#{ui.color('Vagabond:', :bold)} Creating #{ui.color(name, :green)}"
13
14
  do_create
14
15
  ui.info ui.color(' -> CREATED!', :green)
15
16
  end
17
+ true
16
18
  end
17
19
 
18
20
  private
@@ -21,7 +23,7 @@ module Vagabond
21
23
  tmpl = config[:template]
22
24
  if(internal_config[:template_mappings].keys.include?(tmpl))
23
25
  tmpl = internal_config[:template_mappings][tmpl]
24
- elsif(!BASE_TEMPLATES.include?(tmpl))
26
+ elsif(!Vagabond::BASE_TEMPLATES.include?(tmpl))
25
27
  ui.fatal "Template requested for node does not exist: #{tmpl}"
26
28
  raise VagabondError::InvalidTemplate.new(tmpl)
27
29
  end
@@ -32,11 +34,12 @@ module Vagabond
32
34
  config[:original] = tmpl
33
35
  config[:bind] = File.expand_path(vagabondfile.store_directory)
34
36
  ephemeral = Lxc::Ephemeral.new(config)
35
- ephemeral.start!(:fork)
36
37
  e_name = ephemeral.name
37
38
  @internal_config[mappings_key][name] = e_name
38
39
  @internal_config.save
40
+ ephemeral.start!(:fork)
39
41
  @lxc = Lxc.new(e_name)
42
+ @lxc.wait_for_state(:running)
40
43
  end
41
44
 
42
45
  end
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  module Vagabond
2
3
  module Actions
3
4
  module Destroy
@@ -25,28 +26,37 @@ module Vagabond
25
26
 
26
27
  def _destroy
27
28
  name_required!
29
+ @destroyed ||= []
28
30
  if(options[:cluster])
29
- nodes = vagabondfile[:clusters][name] if vagabondfile[:clusters]
30
- if(nodes)
31
+ @cluster_name = name
32
+ @to_destroy = vagabondfile[:clusters][name] if vagabondfile[:clusters]
33
+ if(@to_destroy)
31
34
  ui.info "#{ui.color('Vagabond:', :bold)} Destroying cluster - #{ui.color(name, :red)}"
32
35
  else
33
36
  ui.error "Cluster name provided does not exist: #{name}"
34
- nodes = []
37
+ @to_destroy = []
35
38
  end
36
39
  else
37
- nodes = [name, @leftover_args].flatten.compact
40
+ @to_destroy = [name, @leftover_args].flatten.compact
38
41
  end
39
- nodes.each do |n|
40
- next unless n.is_a?(String)
41
- @name = n
42
- load_configurations
43
- if(lxc.exists?)
44
- ui.info "#{ui.color('Vagabond:', :bold)} Destroying node: #{ui.color(name, :red)}"
45
- do_destroy
46
- ui.info ui.color(' -> DESTROYED', :red)
47
- else
48
- ui.error "Node not created: #{name}"
42
+ remain = @to_destroy - @destroyed
43
+ @name = remain.shift
44
+ configure(:allow_missing)
45
+ if(lxc.exists?)
46
+ ui.info "#{ui.color('Vagabond:', :bold)} Destroying node: #{ui.color(name, :red)}"
47
+ do_destroy
48
+ ui.info ui.color(' -> DESTROYED', :red)
49
+ else
50
+ ui.error "Node not created: #{name}"
51
+ end
52
+ @destroyed << @name
53
+ if(@destroyed.size == @to_destroy.size)
54
+ if(@cluster_name)
55
+ @name = @cluster_name
56
+ configure
49
57
  end
58
+ else
59
+ add_link(:destroy)
50
60
  end
51
61
  end
52
62
 
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  module Vagabond
2
3
  module Actions
3
4
  module Freeze
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  module Vagabond
2
3
  module Actions
3
4
  module Init
@@ -20,16 +21,9 @@ module Vagabond
20
21
  private
21
22
 
22
23
  def empty_vagabondfile_hash
23
- require 'chef/node'
24
- node = Chef::Node.new
25
- node.from_file(
26
- File.join(
27
- File.dirname(__FILE__),
28
- '../cookbooks/vagabond/attributes/default.rb'
29
- )
30
- )
24
+ node = internal_config.cookbook_attributes(:vagabond)
31
25
  nodes = {}
32
- node[:vagabond][:bases].keys.each do |template|
26
+ node[:bases].keys.each do |template|
33
27
  answer = nil
34
28
  until(%w(n y).include?(answer))
35
29
  answer = ui.ask_question("Include template: #{template} ", :default => 'y').downcase
@@ -45,9 +39,12 @@ module Vagabond
45
39
  end
46
40
  end
47
41
  {
42
+ :defaults => {
43
+ :template => 'ubuntu_1204'
44
+ },
48
45
  :nodes => nodes,
49
46
  :clusters => {},
50
- :local_chef_server => {
47
+ :server => {
51
48
  :zero => false,
52
49
  :berkshelf => false,
53
50
  :librarian => false,
@@ -57,7 +54,7 @@ module Vagabond
57
54
  :sudo => true
58
55
  }
59
56
  end
60
-
57
+
61
58
  def do_init
62
59
  if(File.exists?(vagabondfile.path))
63
60
  ui.confirm('Overwrite existing Vagabondfile', true)
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  module Vagabond
2
3
  module Actions
3
4
  module Provision
@@ -13,23 +14,30 @@ module Vagabond
13
14
  ui.error "Node not created: #{name}"
14
15
  end
15
16
  end
16
-
17
+
17
18
  private
18
19
 
19
20
  def do_provision
20
21
  ui.info "#{ui.color('Vagabond:', :bold)} Provisioning node: #{ui.color(name, :magenta)}"
21
- com = "#{sudo} knife bootstrap #{lxc.container_ip(10, true)} -d chef-full -N #{name} -i /opt/hw-lxc-config/id_rsa "
22
- com << "--no-host-key-verify --run-list \"#{config[:run_list].join(',')}\" "
22
+ com = ["bootstrap #{lxc.container_ip(10, true)} -N #{name} -i #{Settings[:ssh_key]}"]
23
+ com << "--no-host-key-verify --run-list \"#{config[:run_list].join(',')}\""
23
24
  if(config[:environment])
24
25
  com << "-E #{config[:environment]}"
25
26
  end
26
- if(options[:knife_opts])
27
- com << options[:knife_opts]
27
+ if(config[:no_lazy_load])
28
+ no_lazy_load_bootstrap = File.join(File.dirname(__FILE__), '..', 'bootstraps/no_lazy_load.erb')
29
+ com << "--template-file #{no_lazy_load_bootstrap}"
30
+ end
31
+ if(config[:chef_10])
32
+ chef_10_bootstrap = File.join(File.dirname(__FILE__), '..', 'bootstraps/chef_10_compat_config.erb')
33
+ com << "--template-file #{chef_10_bootstrap}"
34
+ end
35
+ if(attributes)
36
+ com << "-j '#{attributes}'"
28
37
  end
29
- debug(com)
38
+ cmd = knife_command(com.join(' '), :live_stream => STDOUT, :timeout => 2000)
30
39
  # Send the live stream out since people will generally want to
31
40
  # know what's happening
32
- cmd = Mixlib::ShellOut.new(com, :live_stream => STDOUT, :timeout => 2000)
33
41
  cmd.run_command
34
42
  # NOTE: cmd.status.success? won't be valid, so check for FATAL
35
43
  # TODO: This isn't really the best check, but should be good
@@ -39,7 +47,7 @@ module Vagabond
39
47
  true
40
48
  else
41
49
  ui.info ui.color(' -> PROVISION FAILED', :red)
42
- false
50
+ raise VagabondError::NodeProvisionFailed.new("Failed to provision: #{name}")
43
51
  end
44
52
  end
45
53
 
@@ -1,18 +1,13 @@
1
+ #encoding: utf-8
1
2
  module Vagabond
2
3
  module Actions
3
4
  module Rebuild
4
5
  def _rebuild
5
6
  name_required!
6
7
  ui.info "#{ui.color('Vagabond:', :bold)} Rebuilding #{ui.color(name, :blue)}"
7
- _destroy
8
- @lxc = Lxc.new(name)
9
- _destroy
10
- options[:force_solo] = true
11
- ui.info ui.color(' -> DESTROYED!', :red)
12
- internal_config.run_solo
13
- internal_config[mappings_key].delete(name)
14
- internal_config.save
15
- ui.info ui.color(' -> REBUILT!', :green)
8
+ add_link(:destroy)
9
+ options[:auto_provision] = true
10
+ add_link(:up)
16
11
  end
17
12
  end
18
13
  end
@@ -1,12 +1,19 @@
1
+ #encoding: utf-8
1
2
  module Vagabond
2
3
  module Actions
3
4
  module SSH
5
+
4
6
  def _ssh
5
7
  name_required!
6
8
  if(lxc.exists?)
7
9
  if(lxc.running?)
10
+ key_path = setup_key!
8
11
  ui.info "#{ui.color('Vagabond:', :bold)} SSH connect to: #{ui.color(name, :cyan)}"
9
- exec("#{options[:sudo]}ssh root@#{lxc.container_ip(10, true)} -i /opt/hw-lxc-config/id_rsa -oStrictHostKeyChecking=no")
12
+ command = ["#{options[:sudo]}ssh root@#{lxc.container_ip(10, true)} -i #{Settings[:ssh_key]} -oStrictHostKeyChecking=no"]
13
+ if(@leftover_args)
14
+ command << "\"#{@leftover_args.join(' ')}\""
15
+ end
16
+ exec command.join(' ')
10
17
  else
11
18
  ui.error "Node not running: #{name}"
12
19
  end
@@ -14,6 +21,7 @@ module Vagabond
14
21
  ui.error "Node not created: #{name}"
15
22
  end
16
23
  end
24
+
17
25
  end
18
26
  end
19
27
  end
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  module Vagabond
2
3
  module Actions
3
4
  module Start
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  module Vagabond
2
3
  module Actions
3
4
  module Status
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  module Vagabond
2
3
  module Actions
3
4
  module Thaw
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  module Vagabond
2
3
  module Actions
3
4
  module Up
@@ -17,7 +18,7 @@ module Vagabond
17
18
  name_required!
18
19
  if(lxc.exists?)
19
20
  if(lxc.running?)
20
- ui.error "Node already exists and is running: #{name}"
21
+ ui.warn "Node already exists and is running: #{name}"
21
22
  else
22
23
  ui.info "#{ui.color('Vagabond:', :bold)} Starting node: #{ui.color(name, :green)}"
23
24
  lxc.start
@@ -25,14 +26,28 @@ module Vagabond
25
26
  end
26
27
  end
27
28
  if(options[:parallel])
29
+ # TODO: Need strategy for chains
28
30
  @threads[:up] ||= []
29
- @threads[:up] << Thread.new do
30
- _create
31
- do_provision if options[:auto_provision]
32
- end
31
+ t_holder = Mash.new
32
+ @threads[:up] << t_holder.update(
33
+ :thread => Thread.new{
34
+ sleep(0.01)
35
+ _create
36
+ begin
37
+ do_provision if options[:auto_provision]
38
+ t_holder[:result] = true
39
+ rescue => e
40
+ t_holder[:result] = false
41
+ end
42
+ }
43
+ )
33
44
  else
34
- _create
35
- do_provision if options[:auto_provision]
45
+ if(!lxc.exists?)
46
+ add_link(:create)
47
+ elsif(!lxc.running?)
48
+ add_link(:start)
49
+ end
50
+ add_link(:provision) if options[:auto_provision]
36
51
  end
37
52
  end
38
53
 
@@ -0,0 +1,62 @@
1
+ bash -c '
2
+ <%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
3
+
4
+ exists() {
5
+ if command -v $1 &>/dev/null
6
+ then
7
+ return 0
8
+ else
9
+ return 1
10
+ fi
11
+ }
12
+
13
+ install_sh="https://www.opscode.com/chef/install.sh"
14
+ version_string="-v <%= chef_version %>"
15
+
16
+ if ! exists /usr/bin/chef-client; then
17
+ if exists wget; then
18
+ bash <(wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %> ${install_sh} -O -) ${version_string}
19
+ elif exists curl; then
20
+ bash <(curl -L <%= "--proxy \"#{knife_config[:bootstrap_proxy]}\" " if knife_config[:bootstrap_proxy] %> ${install_sh}) ${version_string}
21
+ else
22
+ echo "Neither wget nor curl found. Please install one and try again." >&2
23
+ exit 1
24
+ fi
25
+ fi
26
+
27
+ mkdir -p /etc/chef
28
+
29
+ cat > /etc/chef/validation.pem <<'EOP'
30
+ <%= validation_key %>
31
+ EOP
32
+ chmod 0600 /etc/chef/validation.pem
33
+
34
+ <% begin %>
35
+ <% if encrypted_data_bag_secret -%>
36
+ cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
37
+ <%= encrypted_data_bag_secret %>
38
+ EOP
39
+ chmod 0600 /etc/chef/encrypted_data_bag_secret
40
+ <% end -%>
41
+ <% rescue; end %>
42
+
43
+ <%# Generate Ohai Hints -%>
44
+ <% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
45
+ mkdir -p /etc/chef/ohai/hints
46
+
47
+ <% @chef_config[:knife][:hints].each do |name, hash| -%>
48
+ cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
49
+ <%= hash.to_json %>
50
+ EOP
51
+ <% end -%>
52
+ <% end -%>
53
+
54
+ cat > /etc/chef/client.rb <<'EOP'
55
+ <%= config_content.sub(':auto', ':info') %>
56
+ EOP
57
+
58
+ cat > /etc/chef/first-boot.json <<'EOP'
59
+ <%= first_boot.to_json %>
60
+ EOP
61
+
62
+ <%= start_chef %>'
@@ -0,0 +1,63 @@
1
+ bash -c '
2
+ <%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
3
+
4
+ exists() {
5
+ if command -v $1 &>/dev/null
6
+ then
7
+ return 0
8
+ else
9
+ return 1
10
+ fi
11
+ }
12
+
13
+ install_sh="https://www.opscode.com/chef/install.sh"
14
+ version_string="-v <%= chef_version %>"
15
+
16
+ if ! exists /usr/bin/chef-client; then
17
+ if exists wget; then
18
+ bash <(wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %> ${install_sh} -O -) ${version_string}
19
+ elif exists curl; then
20
+ bash <(curl -L <%= "--proxy \"#{knife_config[:bootstrap_proxy]}\" " if knife_config[:bootstrap_proxy] %> ${install_sh}) ${version_string}
21
+ else
22
+ echo "Neither wget nor curl found. Please install one and try again." >&2
23
+ exit 1
24
+ fi
25
+ fi
26
+
27
+ mkdir -p /etc/chef
28
+
29
+ cat > /etc/chef/validation.pem <<'EOP'
30
+ <%= validation_key %>
31
+ EOP
32
+ chmod 0600 /etc/chef/validation.pem
33
+
34
+ <% begin %>
35
+ <% if encrypted_data_bag_secret -%>
36
+ cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
37
+ <%= encrypted_data_bag_secret %>
38
+ EOP
39
+ chmod 0600 /etc/chef/encrypted_data_bag_secret
40
+ <% end -%>
41
+ <% rescue; end %>
42
+
43
+ <%# Generate Ohai Hints -%>
44
+ <% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
45
+ mkdir -p /etc/chef/ohai/hints
46
+
47
+ <% @chef_config[:knife][:hints].each do |name, hash| -%>
48
+ cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
49
+ <%= hash.to_json %>
50
+ EOP
51
+ <% end -%>
52
+ <% end -%>
53
+
54
+ cat > /etc/chef/client.rb <<'EOP'
55
+ <%= config_content.sub(':auto', ':info') %>
56
+ Chef::Config[:no_lazy_load] = true
57
+ EOP
58
+
59
+ cat > /etc/chef/first-boot.json <<'EOP'
60
+ <%= first_boot.to_json %>
61
+ EOP
62
+
63
+ <%= start_chef %>'