#!/usr/bin/env ruby # frozen_string_literal: true # Or use Puppet's Ruby: #!/opt/puppetlabs/puppet/bin/ruby # # Call-seq: ./inventory.rb -F form_factor=Server -v require 'motoko' require 'mcollective' include MCollective::RPC # rubocop:disable Style/MixinUsage formatter = Motoko::Formatter.new options = rpcoptions do |parser, local_options| parser.banner = "usage: #{File.basename(__FILE__)} [options]" Motoko::OptionParser.add_inventory_options(parser, formatter) parser.on('--[no-]stats', 'Display statistics') do |v| local_options[:stats] = v end Motoko::OptionParser.add_shortcut_options(parser, formatter, local_options) end options[:stats] = true if options[:stats].nil? util = rpcclient('rpcutil', options: options) util.progress = false (options[:with_class] || []).compact.each do |klass| util.class_filter(klass) end (options[:with_fact] || []).compact.each do |fact| util.fact_filter(fact) end util.inventory do |_, resp| formatter.nodes << Motoko::Node::Choria.new(resp) end puts formatter printrpcstats if options[:stats]