Sha256: cdfe5463511f2d05ff45ddc6977ebf4973971072986a39bf0daed62bd7328da7

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

require 'chef/knife'
require 'knife-spork/runner'

module KnifeSpork
  class SporkNodeRunListAdd < Chef::Knife
    include KnifeSpork::Runner

    banner 'knife spork node run_list add [NODE] [ENTRY[,ENTRY]] (options)'


    option :after,
           :short => "-a ITEM",
           :long  => "--after ITEM",
           :description => "Place the ENTRY in the run list after ITEM"

    def run
      self.config = Chef::Config.merge!(config)

      if @name_args.empty?
        show_usage
        ui.error("You must specify a node name and item to add")
        exit 1
      end

      @object_name = @name_args.first

      @object_secondary_name = @name_args[1..-1].map do |entry|
        entry.split(',').map { |e| e.strip }
      end.flatten.to_s

      run_plugins(:before_noderunlistadd)
      pre_node = load_node(@object_name)
      node_runlistadd
      post_node = load_node(@object_name)
      @object_difference = json_diff(pre_node,post_node).to_s
      run_plugins(:after_noderunlistadd)
    end

    private
    def node_runlistadd
      nrla = Chef::Knife::NodeRunListAdd.new
      nrla.name_args = @name_args
      nrla.config[:editor] = config[:editor]
      nrla.config[:after] = config[:after]
      nrla.run
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
knife-spork-berks-1.3.2 lib/chef/knife/spork-node-runlistadd.rb
knife-spork-1.3.2 lib/chef/knife/spork-node-runlistadd.rb
knife-spork-1.3.1 lib/chef/knife/spork-node-runlistadd.rb
knife-spork-1.3.0 lib/chef/knife/spork-node-runlistadd.rb