class Chef::Knife::NodeRunListRemove

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/node_run_list_remove.rb, line 32
def run
  node = Chef::Node.load(@name_args[0])

  if @name_args.size > 2
    # Check for nested lists and create a single plain one
    entries = @name_args[1..].map do |entry|
      entry.split(",").map(&:strip)
    end.flatten
  else
    # Convert to array and remove the extra spaces
    entries = @name_args[1].split(",").map(&:strip)
  end

  # iterate over the list of things to remove,
  # warning if one of them was not found
  entries.each do |e|
    if node.run_list.find { |rli| e == rli.to_s }
      node.run_list.remove(e)
    else
      ui.warn "#{e} is not in the run list"
      unless /^(recipe|role)\[/.match?(e)
        ui.warn "(did you forget recipe[] or role[] around it?)"
      end
    end
  end

  node.save

  config[:run_list] = true

  output(format_for_display(node))
end