knife-role-replace 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ knife-role-replace
2
+ =================
3
+ Rename a Chef role applied to a node
4
+
5
+ Install
6
+ =======
7
+
8
+ Copy replace.rb into ~/.chef/plugins/knife
9
+
10
+ Gem Install
11
+ ===========
12
+
13
+ ```
14
+ gem install knife-role-replace
15
+ ```
16
+
17
+ How to use
18
+ ==========
19
+
20
+ ```
21
+ knife role replace -s search_role -o old_role_name -n new_role_name
22
+ ```
23
+
24
+ Use the search role name to pick nodes that fit your criteria and replace any role on those hosts.
25
+
26
+ For example, if you had 20 hosts with the role 'base' and the role 'fake-service' applied and you wanted to change the role 'base'
27
+ to say 'linux-base' you would run --
28
+
29
+ ```
30
+ knife role replace -s fake-service -o base -n linux-base
31
+ ```
32
+
33
+ Thats it! The change gets saved to the node and you're ready to go.
@@ -41,22 +41,34 @@ module TP
41
41
  list = @node.run_list
42
42
  ui.msg("Here is the current set of roles on this host: #{list}")
43
43
 
44
- @new_list = list.map do |ele|
45
- old_role_name = config[:old_role]
44
+ begin
46
45
 
47
- if ele == "role[#{config[:old_role]}]"
48
- "role[#{config[:new_role]}]"
49
- else
50
- "#{ele}"
46
+ @new_list = list.map do |ele|
47
+ if rest.get_rest("/roles/#{config[:new_role]}")
48
+ if ele == "role[#{config[:old_role]}]"
49
+ "role[#{config[:new_role]}]"
50
+ else
51
+ "#{ele}"
52
+ end
53
+ end
51
54
  end
52
- end
53
55
 
54
- ui.msg("Fixing up the run_list!\n")
55
- ui.msg("Here is the modified set of roles: #{@new_list}")
56
+ ui.msg("Fixing up the run_list!\n")
57
+ ui.msg("Here is the modified set of roles: #{@new_list}")
56
58
 
57
- @node.run_list(@new_list)
58
- @node.save
59
- ui.msg("Node run_list has been saved on #{host}.") unless !$?.success?
59
+ @node.run_list(@new_list)
60
+ @node.save
61
+
62
+ if $?.success?
63
+ ui.msg("Node run_list has been saved on #{host}.")
64
+ else
65
+ ui.fatal("Node run_list has been NOT saved on #{host}!")
66
+ end
67
+
68
+ rescue Net::HTTPServerException
69
+ ui.fatal("Role: '#{config[:new_role]}' was not found on the server. Did you upload it?")
70
+ end
71
+
60
72
  end
61
73
  end
62
74
 
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module TP
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-role-replace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-06-21 00:00:00.000000000 Z
12
+ date: 2013-06-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Replaces roles on a node when given search criteria
15
15
  email:
@@ -19,6 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - Gemfile
22
+ - README.md
22
23
  - knife-role-replace.gemspec
23
24
  - lib/chef/knife/replace.rb
24
25
  - lib/knife-role-replace.rb