Class: TP::RoleReplace

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/replace.rb

Instance Method Summary collapse

Instance Method Details

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/chef/knife/replace.rb', line 37

def run
  search_role = config[:search_role]
  #search_role = @name_args

  s = TP::search('role', "#{search_role}*")
  s.map do |host|
    node = Chef::Node.load(host)

    list = node.run_list
    ui.msg("Here is the current run_list: #{list}")

    begin

      new_list = list.map do |ele|
        if rest.get_rest("/roles/#{config[:new_role]}")
          if ele == "role[#{config[:old_role]}]"
            "role[#{config[:new_role]}]"
          else
            "#{ele}"
          end
        end
      end

      ui.msg("Fixing up the run_list!\n")
      ui.msg("Here is the modified run_list: #{new_list}")

      node.run_list(new_list)
      node.save

      if $?.success?
        ui.msg("Node run_list has been saved on #{host}.")
      else
        ui.fatal("Node run_list has been NOT saved on #{host}!")
      end

    rescue Net::HTTPServerException 
      ui.fatal("Role: '#{config[:new_role]}' was not found on the server. Did you upload it?")
    end 
  end
end