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,40 +0,0 @@
1
- module ChefLxc
2
- module Resource
3
-
4
- def container(arg=nil)
5
- set_or_return(:container, arg, :kind_of => [String], :required => true)
6
- end
7
-
8
- def lxc
9
- @lxc ||= Lxc.new(
10
- @container,
11
- :base_dir => node[:lxc][:container_directory]
12
- )
13
- end
14
-
15
- def path(arg=nil)
16
- arg ? super(arg) : lxc.expand_path(super(arg))
17
- end
18
-
19
- def self.included(base)
20
- base.class_eval do
21
- def initialize(*args)
22
- super
23
- @container = nil
24
- end
25
- end
26
- end
27
- end
28
- end
29
-
30
- class Chef
31
- class Resource
32
- class LxcTemplate < Template
33
- include ChefLxc::Resource
34
- end
35
-
36
- class LxcFile < File
37
- include ChefLxc::Resource
38
- end
39
- end
40
- end
@@ -1,84 +0,0 @@
1
- class LxcFileConfig
2
-
3
- attr_reader :network
4
- attr_reader :base
5
-
6
- class << self
7
- def generate_config(resource)
8
- config = []
9
- config << "lxc.utsname = #{resource.utsname}"
10
- if(resource.aa_profile)
11
- config << "lxc.aa_profile = #{resource.aa_profile}"
12
- end
13
- [resource.network].flatten.each do |net_hash|
14
- nhsh = Mash.new(net_hash)
15
- flags = nhsh.delete(:flags)
16
- %w(type link).each do |k|
17
- config << "lxc.network.#{k} = #{nhsh.delete(k)}" if nhsh[k]
18
- end
19
- nhsh.each_pair do |k,v|
20
- config << "lxc.network.#{k} = #{v}"
21
- end
22
- if(flags)
23
- config << "lxc.network.flags = #{flags}"
24
- end
25
- end
26
- if(resource.cap_drop)
27
- config << "lxc.cap.drop = #{Array(resource.cap_drop).join(' ')}"
28
- end
29
- %w(pts tty arch devttydir mount mount_entry rootfs rootfs_mount pivotdir).each do |k|
30
- config << "lxc.#{k.sub('_', '.')} = #{resource.send(k)}" if resource.send(k)
31
- end
32
- prefix = 'lxc.cgroup'
33
- resource.cgroup.each_pair do |key, value|
34
- if(value.is_a?(Array))
35
- value.each do |val|
36
- config << "#{prefix}.#{key} = #{val}"
37
- end
38
- else
39
- config << "#{prefix}.#{key} = #{value}"
40
- end
41
- end
42
- config.join("\n") + "\n"
43
- end
44
-
45
- end
46
-
47
- def initialize(path)
48
- raise 'LXC config file not found' unless File.exists?(path)
49
- @path = path
50
- @network = []
51
- @base = Mash.new
52
- parse!
53
- end
54
-
55
- private
56
-
57
- def parse!
58
- cur_net = nil
59
- File.readlines(@path).each do |line|
60
- if(line.start_with?('lxc.network'))
61
- parts = line.split('=')
62
- name = parts.first.split('.').last.strip
63
- if(name.to_sym == :type)
64
- @network << cur_net if cur_net
65
- cur_net = Mash.new
66
- end
67
- if(cur_net)
68
- cur_net[name] = parts.last.strip
69
- else
70
- raise "Expecting 'lxc.network.type' to start network config block. Found: 'lxc.network.#{name}'"
71
- end
72
- else
73
- parts = line.split('=')
74
- name = parts.first.sub('lxc.', '').strip
75
- if(@base[name])
76
- @base[name] = [@base[name], parts.last.strip].flatten
77
- else
78
- @base[name] = parts.last
79
- end
80
- end
81
- end
82
- @network << cur_net if cur_net
83
- end
84
- end
@@ -1,51 +0,0 @@
1
- unless(defined?(LxcMonkey))
2
- require 'chef/resource/execute'
3
- require 'chef/provider/execute'
4
-
5
- module LxcMonkey
6
- module Provider
7
- class << self
8
- def included(klass)
9
- klass.class_eval do
10
- alias_method :non_monkey_shell_out!, :shell_out!
11
- alias_method :shell_out!, :monkey_shell_out!
12
- end
13
- end
14
- end
15
-
16
- def monkey_shell_out!(com, opts)
17
- if(str = @new_resource.stream_output)
18
- opts[:live_stream] = str.kind_of?(IO) ? str : STDOUT
19
- end
20
- non_monkey_shell_out!(com, opts)
21
- end
22
- end
23
- module Resource
24
-
25
- class << self
26
- def included(klass)
27
- klass.class_eval do
28
- alias_method :non_monkey_initialize, :initialize
29
- alias_method :initialize, :monkey_initialize
30
- end
31
- end
32
- end
33
-
34
- def monkey_initialize(*args)
35
- non_monkey_initialize(*args)
36
- @stream_output = nil
37
- end
38
-
39
- def stream_output(arg=nil)
40
- set_or_return(
41
- :stream_output,
42
- arg,
43
- :kind_of => [TrueClass,FalseClass,IO]
44
- )
45
- end
46
- end
47
- end
48
-
49
- Chef::Resource::Execute.send(:include, LxcMonkey::Resource)
50
- Chef::Provider::Execute.send(:include, LxcMonkey::Provider)
51
- end
@@ -1,12 +0,0 @@
1
- name 'lxc'
2
- maintainer 'Chris Roberts'
3
- maintainer_email 'chrisroberts.code@gmail.com'
4
- license 'Apache 2.0'
5
- description 'Chef driven Linux Containers'
6
- long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7
- version '1.0.1'
8
-
9
- supports 'ubuntu'
10
-
11
- suggests 'omnibus_updater'
12
- suggests 'bridger'
@@ -1,75 +0,0 @@
1
- require 'securerandom'
2
-
3
- def load_current_resource
4
- @lxc = ::Lxc.new(
5
- new_resource.name,
6
- :base_dir => node[:lxc][:container_directory],
7
- :dnsmasq_lease_file => node[:lxc][:dnsmasq_lease_file]
8
- )
9
- new_resource.utsname new_resource.name unless new_resource.utsname
10
- new_resource.rootfs @lxc.rootfs.to_path unless new_resource.rootfs
11
- new_resource.default_bridge node[:lxc][:bridge] unless new_resource.default_bridge
12
- new_resource.mount @lxc.path.join('fstab').to_path unless new_resource.mount
13
- config = LxcFileConfig.new(@lxc.container_config)
14
- if((new_resource.network.nil? || new_resource.network.empty?))
15
- if(config.network.empty?)
16
- default_net = {
17
- :type => :veth,
18
- :link => new_resource.default_bridge,
19
- :flags => :up,
20
- :hwaddr => "00:16:3e#{SecureRandom.hex(3).gsub(/(..)/, ':\1')}"
21
- }
22
- else
23
- default_net = config.network.first
24
- default_net.delete(:ipv4) if default_net.has_key?(:ipv4)
25
- default_net.merge!(:link => new_resource.default_bridge)
26
- end
27
- new_resource.network(default_net)
28
- else
29
- [new_resource.network].flatten.each_with_index do |net_hash, idx|
30
- if(config.network[idx].nil? || config.network[idx][:hwaddr].nil?)
31
- net_hash[:hwaddr] ||= "00:16:3e#{SecureRandom.hex(3).gsub(/(..)/, ':\1')}"
32
- end
33
- end
34
- end
35
- new_resource.cgroup(
36
- Chef::Mixin::DeepMerge.merge(
37
- Mash.new(
38
- 'devices.deny' => 'a',
39
- 'devices.allow' => [
40
- 'c *:* m',
41
- 'b *:* m',
42
- 'c 1:3 rwm',
43
- 'c 1:5 rwm',
44
- 'c 5:1 rwm',
45
- 'c 5:0 rwm',
46
- 'c 1:9 rwm',
47
- 'c 1:8 rwm',
48
- 'c 136:* rwm',
49
- 'c 5:2 rwm',
50
- 'c 254:0 rwm',
51
- 'c 10:229 rwm',
52
- 'c 10:200 rwm',
53
- 'c 1:7 rwm',
54
- 'c 10:228 rwm',
55
- 'c 10:232 rwm'
56
- ]
57
- ),
58
- new_resource.cgroup
59
- )
60
- )
61
- end
62
-
63
- action :create do
64
- _lxc = @lxc
65
-
66
- directory @lxc.path.to_path do
67
- action :create
68
- end
69
-
70
- file "lxc update_config[#{new_resource.utsname}]" do
71
- path _lxc.container_config.to_path
72
- content LxcFileConfig.generate_config(new_resource)
73
- mode 0644
74
- end
75
- end
@@ -1,354 +0,0 @@
1
- def load_current_resource
2
- @lxc = ::Lxc.new(
3
- new_resource.name,
4
- :base_dir => node[:lxc][:container_directory],
5
- :dnsmasq_lease_file => node[:lxc][:dnsmasq_lease_file]
6
- )
7
- new_resource.subresources.map! do |s_r|
8
- s_r.first.run_context = run_context
9
- s_r.first.instance_eval(&s_r.last)
10
- s_r.first
11
- end
12
-
13
- # TODO: Use some actual logic here, sheesh
14
- if(new_resource.static_ip && new_resource.static_gateway.nil?)
15
- raise "Static gateway must be defined when static IP is provided (Container: #{new_resource.name})"
16
- end
17
- new_resource.default_bridge node[:lxc][:bridge] unless new_resource.default_bridge
18
- node.run_state[:lxc] ||= Mash.new
19
- node.run_state[:lxc][:meta] ||= Mash.new
20
- node.run_state[:lxc][:meta][new_resource.name] = Mash.new(
21
- :new_container => !@lxc.exists?,
22
- :lxc => @lxc
23
- )
24
- end
25
-
26
- action :create do
27
- _lxc = @lxc # for use inside resources
28
- stopped_end_state = _lxc.stopped?
29
-
30
- #### Add custom key for host based interactions
31
- directory '/opt/hw-lxc-config' do
32
- recursive true
33
- end
34
-
35
- execute 'lxc host_ssh_key' do
36
- command "ssh-keygen -P '' -f /opt/hw-lxc-config/id_rsa"
37
- creates '/opt/hw-lxc-config/id_rsa'
38
- end
39
-
40
- #### Create container
41
- lxc new_resource.name do
42
- if(new_resource.clone)
43
- action :clone
44
- base_container new_resource.clone
45
- else
46
- action :create
47
- template new_resource.template
48
- template_opts new_resource.template_opts
49
- end
50
- end
51
-
52
- #### Create container configuration bits
53
- if(new_resource.default_config)
54
- lxc_config new_resource.name do
55
- action :create
56
- default_bridge new_resource.default_bridge
57
- end
58
- end
59
-
60
- if(new_resource.default_fstab)
61
- lxc_fstab "proc[#{new_resource.name}]" do
62
- container new_resource.name
63
- file_system 'proc'
64
- mount_point 'proc'
65
- type 'proc'
66
- options %w(nodev noexec nosuid)
67
- end
68
-
69
- lxc_fstab "sysfs[#{new_resource.name}]" do
70
- container new_resource.name
71
- file_system 'sysfs'
72
- mount_point 'sys'
73
- type 'sysfs'
74
- options 'default'
75
- end
76
- end
77
-
78
- if(new_resource.static_ip)
79
- lxc_interface "eth0[#{new_resource.name}]" do
80
- container new_resource.name
81
- device 'eth0'
82
- address new_resource.static_ip
83
- netmask new_resource.static_netmask
84
- gateway new_resource.static_gateway
85
- end
86
- end
87
-
88
- ruby_block "LXC #{new_resource.name} - Run subresources" do
89
- block do
90
- new_resource.subresources.each do |s_r|
91
- s_r.run_action(:create)
92
- end
93
- end
94
- not_if do
95
- new_resource.subresources.empty?
96
- end
97
- end
98
-
99
- template @lxc.path.join('fstab').to_path do
100
- source 'fstab.erb'
101
- cookbook 'lxc'
102
- variables :container => new_resource.name
103
- only_if do
104
- node.run_state[:lxc][:fstabs] &&
105
- node.run_state[:lxc][:fstabs][new_resource.name]
106
- end
107
- mode 0644
108
- end
109
-
110
- template @lxc.rootfs.join('etc/network/interfaces').to_path do
111
- source 'interface.erb'
112
- cookbook 'lxc'
113
- variables :container => new_resource.name
114
- mode 0644
115
- only_if do
116
- node.run_state[:lxc][:interfaces] &&
117
- node.run_state[:lxc][:interfaces][new_resource.name]
118
- end
119
- end
120
-
121
- #### Ensure host has ssh access into container
122
- directory @lxc.rootfs.join('root/.ssh').to_path
123
-
124
- template @lxc.rootfs.join('root/.ssh/authorized_keys').to_path do
125
- source 'file_content.erb'
126
- cookbook 'lxc'
127
- mode 0600
128
- variables(:path => '/opt/hw-lxc-config/id_rsa.pub')
129
- end
130
-
131
- #### Use cached chef package from host if available
132
- if(%w(debian ubuntu).include?(new_resource.template) && system('ls /opt/chef*.deb 2>1 > /dev/null'))
133
- if(::File.directory?('/opt'))
134
- file_name = Dir.new('/opt').detect do |item|
135
- item.start_with?('chef') && item.end_with?('.deb')
136
- end
137
- end
138
-
139
- execute "lxc copy_chef_full[#{new_resource.name}]" do
140
- command "cp /opt/#{file_name} #{_lxc.rootfs.join('opt')}"
141
- not_if do
142
- file_name.nil? || !new_resource.chef_enabled || _lxc.rootfs.join('opt', file_name).exist?
143
- end
144
- end
145
-
146
- execute "lxc install_chef_full[#{new_resource.name}]" do
147
- action :nothing
148
- command "chroot #{_lxc.rootfs} dpkg -i #{::File.join('/opt', file_name)}"
149
- subscribes :run, "execute[lxc copy_chef_full[#{new_resource.name}]]", :immediately
150
- end
151
- elsif(new_resource.chef_enabled)
152
- pkg_coms = ['update -y -q', 'upgrade -y -q','install curl -y -q']
153
- if(!new_resource.template.to_s.scan(%r{debian|ubuntu}).empty?)
154
- pkg_man = 'apt-get'
155
- elsif(!new_resource.template.to_s.scan(%r{fedora|centos}).empty?)
156
- pkg_man = 'yum'
157
- end
158
- if(pkg_man)
159
- new_resource.initialize_commands(
160
- pkg_coms.map do |c|
161
- "#{pkg_man} #{c}"
162
- end + new_resource.initialize_commands
163
- )
164
- end
165
- end
166
-
167
- ruby_block "lxc lock_default_users" do
168
- block do
169
- contents = ::File.readlines(_lxc.rootfs.join('etc/shadow').to_path)
170
- ::File.open(_lxc.rootfs.join('etc/shadow').to_path, 'w') do |file|
171
- contents.each do |line|
172
- parts = line.split(':')
173
- if(node[:lxc][:user_locks].include?(parts.first) && !parts[1].start_with?('!'))
174
- parts[1] = "!#{parts[1]}"
175
- end
176
- file.write parts.join(':')
177
- end
178
- end
179
- end
180
- only_if do
181
- ::File.readlines(_lxc.rootfs.join('etc/shadow').to_path).detect do |line|
182
- parts = line.split(':')
183
- node[:lxc][:user_locks].include?(parts.first) && !parts[1].start_with?('!')
184
- end
185
- end
186
- end
187
-
188
- ruby_block "lxc default_password_scrub" do
189
- block do
190
- contents = ::File.readlines(_lxc.rootfs.join('etc/shadow').to_path)
191
- ::File.open(_lxc.rootfs.join('etc/shadow'), 'w') do |file|
192
- contents.each do |line|
193
- if(line.start_with?('root:'))
194
- line.sub!(%r{root:.+?:}, 'root:*')
195
- end
196
- file.write line
197
- end
198
- end
199
- end
200
- not_if "grep 'root:*' #{_lxc.rootfs.join('etc/shadow').to_path}"
201
- end
202
-
203
- ruby_block "lxc start[#{new_resource.name}]" do
204
- block do
205
- _lxc.start
206
- end
207
- only_if do
208
- _lxc.rootfs.join('etc/chef/first_run.json').exist? ||
209
- !new_resource.container_commands.empty? ||
210
- (node.run_state[:lxc][:meta][new_resource.name][:new_container] && new_resource.initialize_commands)
211
- end
212
- end
213
-
214
- #### Have initialize commands for the container? Run them now
215
- ruby_block "lxc initialize_commands[#{new_resource.name}]" do
216
- block do
217
- new_resource.initialize_commands.each do |cmd|
218
- Chef::Log.info "Running command on #{new_resource.name}: #{cmd}"
219
- _lxc.container_command(cmd, 2)
220
- end
221
- end
222
- only_if do
223
- node.run_state[:lxc][:meta][new_resource.name][:new_container] &&
224
- !new_resource.initialize_commands.empty?
225
- end
226
- end
227
-
228
- # Make sure we have chef in the container
229
- remote_file "lxc chef_install_script[#{new_resource.name}]" do
230
- source "http://opscode.com/chef/install.sh"
231
- path _lxc.rootfs.join('opt/chef-install.sh').to_path
232
- action :create_if_missing
233
- only_if do
234
- new_resource.chef_enabled && !_lxc.rootfs.join('usr/bin/chef-client').exist?
235
- end
236
- end
237
-
238
- ruby_block "lxc install_chef[#{new_resource.name}]" do
239
- block do
240
- _lxc.container_command('bash /opt/chef-install.sh')
241
- end
242
- action :create
243
- only_if do
244
- new_resource.chef_enabled &&
245
- !_lxc.rootfs.join('usr/bin/chef-client').exist? &&
246
- _lxc.rootfs.join('opt/chef-install.sh').exist?
247
- end
248
- end
249
-
250
- #### Setup chef related bits within container
251
- directory @lxc.rootfs.join('etc/chef').to_path do
252
- action :create
253
- mode 0755
254
- only_if{ new_resource.chef_enabled }
255
- end
256
-
257
- template "lxc chef-config[#{new_resource.name}]" do
258
- source 'client.rb.erb'
259
- cookbook 'lxc'
260
- path _lxc.rootfs.join('etc/chef/client.rb').to_path
261
- variables(
262
- :validation_client => new_resource.validation_client || Chef::Config[:validation_client_name],
263
- :node_name => new_resource.node_name || "#{node.name}-#{new_resource.name}",
264
- :server_uri => new_resource.server_uri || Chef::Config[:chef_server_url],
265
- :chef_environment => new_resource.chef_environment || '_default'
266
- )
267
- mode 0644
268
- only_if{ new_resource.chef_enabled }
269
- end
270
-
271
- file "lxc chef-validator[#{new_resource.name}]" do
272
- path _lxc.rootfs.join('etc/chef/validator.pem').to_path
273
- content new_resource.validator_pem || node[:lxc][:validator_pem]
274
- mode 0600
275
- only_if{ new_resource.chef_enabled && !_lxc.rootfs.join('etc/chef/client.pem').exist? }
276
- end
277
-
278
- file "lxc chef-runlist[#{new_resource.name}]" do
279
- path _lxc.rootfs.join('etc/chef/first_run.json').to_path
280
- content({:run_list => new_resource.run_list}.to_json)
281
- only_if do
282
- new_resource.chef_enabled && !_lxc.rootfs.join('etc/chef/client.pem').exist?
283
- end
284
- mode 0644
285
- end
286
-
287
- file "lxc chef-data-bag-secret[#{new_resource.name}]" do
288
- path _lxc.rootfs.join('etc/chef/encrypted_data_bag_secret').to_path
289
- content(
290
- ::File.exists?(new_resource.data_bag_secret_file) ? ::File.open(new_resource.data_bag_secret_file, "rb").read : ''
291
- )
292
- mode 0600
293
- only_if do
294
- new_resource.chef_enabled &&
295
- new_resource.copy_data_bag_secret_file &&
296
- ::File.exists?(new_resource.copy_data_bag_secret_file)
297
- end
298
- end
299
-
300
- #### Let chef configure the container
301
- # NOTE: We run chef-client if the validator.pem exists and the
302
- # client.pem file does not exist.
303
- ruby_block "lxc run_chef[#{new_resource.name}]" do
304
- block do
305
- cmd = 'chef-client -K /etc/chef/validator.pem -c /etc/chef/client.rb -j /etc/chef/first_run.json'
306
- Chef::Log.info "Running command on #{new_resource.name}: #{cmd}"
307
- _lxc.container_command(cmd, new_resource.chef_retries)
308
- end
309
- only_if do
310
- new_resource.chef_enabled &&
311
- _lxc.rootfs.join('etc/chef/validator.pem').exist? &&
312
- !_lxc.rootfs.join('etc/chef/client.pem').exist?
313
- end
314
- end
315
-
316
- #### Have commands for the container? Run them now
317
- ruby_block "lxc container_commands[#{new_resource.name}]" do
318
- block do
319
- new_resource.container_commands.each do |cmd|
320
- _lxc.container_command(cmd, 2)
321
- end
322
- end
323
- not_if do
324
- new_resource.container_commands.empty?
325
- end
326
- end
327
-
328
- # NOTE: If the container was not running before we started, make
329
- # sure we leave it in a stopped state
330
- ruby_block "lxc shutdown[#{new_resource.name}]" do
331
- block do
332
- _lxc.shutdown
333
- end
334
- only_if do
335
- stopped_end_state && _lxc.running?
336
- end
337
- end
338
-
339
- #### Clean up after chef if it's enabled
340
- file @lxc.rootfs.join('etc/chef/first_run.json').to_path do
341
- action :delete
342
- end
343
-
344
- file @lxc.rootfs.join('etc/chef/validator.pem').to_path do
345
- action :delete
346
- end
347
-
348
- end
349
-
350
- action :delete do
351
- lxc new_resource.name do
352
- action :delete
353
- end
354
- end