Class: TP::RoleAdd

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

Instance Method Summary collapse

Instance Method Details

#runObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/chef/knife/replace.rb', line 100

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

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

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

    begin
      if rest.get_rest("/roles/#{config[:new_role]}")
        new_list = list.to_a.insert("#{config[:position]}".to_i, "role[#{config[:new_role]}]")
      end

      ui.msg("Here is your new run_list: #{new_list}")
      node.run_list(new_list)
      node.save

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