knife-role-convert 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -1
- data/lib/chef/knife/role_convert.rb +0 -3
- data/lib/chef/role_converter.rb +13 -13
- data/lib/chef/role_converter/templates/recipe.erb +2 -2
- data/lib/chef/role_converter/version.rb +1 -1
- data/spec/data/roles/simple_role.rb +9 -2
- data/spec/unit/role_convert_spec.rb +7 -3
- metadata +5 -5
data/Rakefile
CHANGED
@@ -41,11 +41,8 @@ class Chef
|
|
41
41
|
ui.error("You must supply the name of the role you wish to convert")
|
42
42
|
exit 1
|
43
43
|
end
|
44
|
-
|
45
44
|
role = @name_args[0]
|
46
|
-
|
47
45
|
converter = Chef::RoleConverter.new(role, config)
|
48
|
-
converter.convert
|
49
46
|
puts converter.generate_recipe
|
50
47
|
end
|
51
48
|
end
|
data/lib/chef/role_converter.rb
CHANGED
@@ -26,7 +26,7 @@ class Chef
|
|
26
26
|
attr_reader :role, :cookbook, :recipe
|
27
27
|
attr_accessor :attributes, :dependencies, :run_list
|
28
28
|
|
29
|
-
def initialize(role, config={})
|
29
|
+
def initialize(role, config = {})
|
30
30
|
@role = Chef::Role.from_disk(role)
|
31
31
|
@config = config
|
32
32
|
@recipe = config[:recipe] || @role.name
|
@@ -39,7 +39,7 @@ class Chef
|
|
39
39
|
@dependencies = []
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def convert_role
|
43
43
|
convert_attributes(role.default_attributes, "default")
|
44
44
|
convert_attributes(role.override_attributes, "override")
|
45
45
|
convert_runlist
|
@@ -48,16 +48,15 @@ class Chef
|
|
48
48
|
def convert_attributes(attrs, type, parents=[])
|
49
49
|
# XXX this whole bit stinks, redo it later
|
50
50
|
attrs.each do |attribute, value|
|
51
|
+
# detect hashes and recursively descend to the bottommost level of nesting
|
51
52
|
if value.is_a? Hash
|
52
|
-
|
53
|
-
|
53
|
+
# make a copy of the parent path and add our current location before recurring
|
54
|
+
new_parents = parents.dup
|
55
|
+
new_parents << attribute
|
56
|
+
convert_attributes(value, type, new_parents)
|
54
57
|
else
|
55
|
-
|
56
|
-
|
57
|
-
else
|
58
|
-
attr_path = parents.map {|a| "['#{a}']" }.join() + "['#{attribute}']"
|
59
|
-
end
|
60
|
-
attributes[type] << "#{attr_path} = #{value.pretty_inspect}"
|
58
|
+
attr_path = parents.map { |a| "['#{a}']" }.join() + "['#{attribute}']"
|
59
|
+
attributes[type].push("node.#{type}#{attr_path} = #{value.pretty_inspect}")
|
61
60
|
end
|
62
61
|
end
|
63
62
|
end
|
@@ -69,16 +68,17 @@ class Chef
|
|
69
68
|
unless dependencies.member? cookbook
|
70
69
|
dependencies << cookbook
|
71
70
|
end
|
72
|
-
run_list
|
71
|
+
run_list.push("include_recipe '#{entry.name}'\n")
|
73
72
|
elsif entry.role?
|
74
73
|
# XXX process recursively ?
|
75
|
-
run_list
|
76
|
-
run_list
|
74
|
+
run_list.push("# XXX detected role in run_list: #{entry.name}\n")
|
75
|
+
run_list.push("# include_recipe 'role_cookbook::#{entry.name}'\n")
|
77
76
|
end
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
81
80
|
def generate_recipe
|
81
|
+
convert_role
|
82
82
|
template = IO.read(Chef::RoleConverter::RECIPE_TEMPLATE).chomp
|
83
83
|
eruby = Erubis::Eruby.new(template)
|
84
84
|
context = {
|
@@ -10,14 +10,14 @@
|
|
10
10
|
<% unless @default_attributes.empty? -%>
|
11
11
|
# default attributes
|
12
12
|
<% @default_attributes.each do |line| -%>
|
13
|
-
|
13
|
+
<%= line -%>
|
14
14
|
<% end -%>
|
15
15
|
|
16
16
|
<% end -%>
|
17
17
|
<% unless @override_attributes.empty? -%>
|
18
18
|
# override attributes
|
19
19
|
<% @override_attributes.each do |line| -%>
|
20
|
-
|
20
|
+
<%= line -%>
|
21
21
|
<% end -%>
|
22
22
|
|
23
23
|
<% end -%>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
name 'simple_role'
|
2
|
-
description 'simple test role for knife-role-
|
2
|
+
description 'simple test role for knife-role-convert'
|
3
3
|
|
4
4
|
run_list(
|
5
5
|
"recipe[foo]"
|
@@ -8,9 +8,16 @@ run_list(
|
|
8
8
|
override_attributes(
|
9
9
|
"foo" => {
|
10
10
|
"unicorn" => {
|
11
|
-
"collect_tears" => true
|
11
|
+
"collect_tears" => true,
|
12
|
+
"nested" => {
|
13
|
+
"should_not_inspect_the_contents" => [
|
14
|
+
{ :lambda => 'lambda' },
|
15
|
+
{ :lambda => 'mu' }
|
16
|
+
]
|
17
|
+
}
|
12
18
|
}
|
13
19
|
},
|
14
20
|
"bar" => 1,
|
21
|
+
"baz" => 2.2,
|
15
22
|
"quux" => %w{unos dos tres}
|
16
23
|
)
|
@@ -32,9 +32,13 @@ class Chef
|
|
32
32
|
|
33
33
|
it "process nested attributes" do
|
34
34
|
simple_role.convert_attributes(simple_role.role.override_attributes, "override")
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
simple_role.attributes['override'].should eq [
|
36
|
+
"node.override['foo']['unicorn']['collect_tears'] = true\n",
|
37
|
+
"node.override['foo']['unicorn']['nested']['should_not_inspect_the_contents'] = [{:lambda=>\"lambda\"}, {:lambda=>\"mu\"}]\n",
|
38
|
+
"node.override['bar'] = 1\n",
|
39
|
+
"node.override['baz'] = 2.2\n",
|
40
|
+
"node.override['quux'] = [\"unos\", \"dos\", \"tres\"]\n"
|
41
|
+
]
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-role-convert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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: 2013-
|
12
|
+
date: 2013-08-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mixlib-cli
|
@@ -91,7 +91,7 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
-
description:
|
94
|
+
description: knife plugin for converting roles to recipes
|
95
95
|
email: msf@kisoku.net
|
96
96
|
executables: []
|
97
97
|
extensions: []
|
@@ -109,7 +109,7 @@ files:
|
|
109
109
|
- spec/unit/role_convert_spec.rb
|
110
110
|
- spec/support/spec_helper.rb
|
111
111
|
- spec/data/roles/simple_role.rb
|
112
|
-
homepage: http://
|
112
|
+
homepage: http://github.com/kisoku/knife-role-convert
|
113
113
|
licenses:
|
114
114
|
- Apache 2.0
|
115
115
|
post_install_message:
|
@@ -133,6 +133,6 @@ rubyforge_project:
|
|
133
133
|
rubygems_version: 1.8.23
|
134
134
|
signing_key:
|
135
135
|
specification_version: 3
|
136
|
-
summary:
|
136
|
+
summary: knife plugin for converting roles to recipes
|
137
137
|
test_files: []
|
138
138
|
has_rdoc: true
|