Class: Bolt::Inventory

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/inventory.rb,
lib/bolt/inventory/group.rb

Defined Under Namespace

Classes: Group, ValidationError, WildcardError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, config = nil) ⇒ Inventory

Returns a new instance of Inventory.



48
49
50
51
52
53
54
55
# File 'lib/bolt/inventory.rb', line 48

def initialize(data, config = nil)
  @logger = Logging.logger[self]
  # Config is saved to add config options to targets
  @config = config || Bolt::Config.new
  @data = data ||= {}
  @groups = Group.new(data.merge('name' => 'all'))
  @group_lookup = {}
end

Class Method Details

.default_pathsObject



35
36
37
# File 'lib/bolt/inventory.rb', line 35

def self.default_paths
  [File.expand_path(File.join('~', '.puppetlabs', 'bolt', 'inventory.yaml'))]
end

.from_config(config) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/bolt/inventory.rb', line 39

def self.from_config(config)
  data = Bolt::Util.read_config_file(config[:inventoryfile], default_paths, 'inventory')

  inventory = new(data, config)
  inventory.validate
  inventory.collect_groups
  inventory
end

Instance Method Details

#collect_groupsObject



61
62
63
64
# File 'lib/bolt/inventory.rb', line 61

def collect_groups
  # Provide a lookup map for finding a group by name
  @group_lookup = @groups.collect_groups
end

#config_for(node_name) ⇒ Object

Should this be a public method?



77
78
79
80
81
82
# File 'lib/bolt/inventory.rb', line 77

def config_for(node_name)
  data = @groups.data_for(node_name)
  if data
    Bolt::Util.symbolize_keys(data['config'])
  end
end

#get_targets(targets) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/bolt/inventory.rb', line 66

def get_targets(targets)
  targets = expand_targets(targets)
  targets = if targets.is_a? Array
              targets.flatten.uniq(&:name)
            else
              [targets]
            end
  targets.map { |t| update_target(t) }
end

#groups_in(node_name) ⇒ Object

PRIVATE ####

For debugging only now



87
88
89
# File 'lib/bolt/inventory.rb', line 87

def groups_in(node_name)
  @groups.data_for(node_name)['groups'] || {}
end

#validateObject



57
58
59
# File 'lib/bolt/inventory.rb', line 57

def validate
  @groups.validate
end