lib/octofacts_updater/cli.rb
# Constructor.
#
# argv - The Array with command line arguments.
Constructor.
argv - The Array with command line arguments.
Constructor . argv - The Array with command line arguments .
def handle_action_bulk
      facts_to_index = @config.fetch("index", {})["indexed_facts"]
      unless facts_to_index.is_a?(Array)
        raise ArgumentError, "Must declare index:indexed_facts in configuration to use bulk update"
      end
      nodes = nodes_for_bulk
      if nodes.empty?
        raise ArgumentError, "Cannot run bulk update with no nodes to check"
      end
      path = opts[:path] || @config.fetch("index", {})["node_path"]
      paths = []
      fixtures = nodes.map do |hostname|
        if opts[:quick] && path && File.file?(File.join(path, "#{hostname}.yaml"))
          OctofactsUpdater::Fixture.load_file(hostname, File.join(path, "#{hostname}.yaml"))
        else
          fixture = OctofactsUpdater::Fixture.make(hostname, @config)
          if path && File.directory?(path)
            fixture.write_file(File.join(path, "#{hostname}.yaml"))
            paths << File.join(path, "#{hostname}.yaml")
          end
          fixture
        end
      end
      index = OctofactsUpdater::FactIndex.load_file(index_file)
      index.reindex(facts_to_index, fixtures)
      index.write_file
      paths << index_file
      if opts[:github] && opts[:github][:enabled]
        OctofactsUpdater::Service::GitHub.run(config["github"]["base_directory"], paths, @config)
      end
    end
def handle_action_bulk facts_to_index = @config . fetch ( "index" , { } ) [ "indexed_facts" ] unless facts_to_index . is_a? ( Array ) raise ArgumentError , "Must declare index:indexed_facts in configuration to use bulk update" end nodes = nodes_for_bulk if nodes . empty? raise ArgumentError , "Cannot run bulk update with no nodes to check" end path = opts [ :path ] || @config . fetch ( "index" , { } ) [ "node_path" ] paths = [ ] fixtures = nodes . map do | hostname | if opts [ :quick ] && path && File . file? ( File . join ( path , "#{hostname}.yaml" ) ) OctofactsUpdater :: Fixture . load_file ( hostname , File . join ( path , "#{hostname}.yaml" ) ) else fixture = OctofactsUpdater :: Fixture . make ( hostname , @config ) if path && File . directory? ( path ) fixture . write_file ( File . join ( path , "#{hostname}.yaml" ) ) paths << File . join ( path , "#{hostname}.yaml" ) end fixture end end index = OctofactsUpdater :: FactIndex . load_file ( index_file ) index . reindex ( facts_to_index , fixtures ) index . write_file paths << index_file if opts [ :github ] && opts [ :github ] [ :enabled ] OctofactsUpdater :: Service :: GitHub . run ( config [ "github" ] [ "base_directory" ] , paths , @config ) end end
Constructor.
Constructor .