Class: MCollective::Util::Playbook::Nodes::YamlNodes

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/util/playbook/nodes/yaml_nodes.rb

Instance Method Summary collapse

Constructor Details

#initializeYamlNodes

Returns a new instance of YamlNodes.



8
9
10
11
# File 'lib/mcollective/util/playbook/nodes/yaml_nodes.rb', line 8

def initialize
  @group = nil
  @file = nil
end

Instance Method Details

#dataObject



35
36
37
# File 'lib/mcollective/util/playbook/nodes/yaml_nodes.rb', line 35

def data
  @_data ||= YAML.safe_load(File.read(@file))
end

#discoverObject

Performs the PQL query and extracts certnames



40
41
42
# File 'lib/mcollective/util/playbook/nodes/yaml_nodes.rb', line 40

def discover
  data[@group]
end

#from_hash(data) ⇒ PqlNodes

Initialize the nodes source from a hash

Parameters:

  • data (Hash)

    input with ‘group` and `source` keys

Returns:



28
29
30
31
32
33
# File 'lib/mcollective/util/playbook/nodes/yaml_nodes.rb', line 28

def from_hash(data)
  @group = data["group"]
  @file = data["source"]

  self
end

#prepareObject



13
# File 'lib/mcollective/util/playbook/nodes/yaml_nodes.rb', line 13

def prepare; end

#validate_configuration!Object



15
16
17
18
19
20
21
22
# File 'lib/mcollective/util/playbook/nodes/yaml_nodes.rb', line 15

def validate_configuration!
  raise("No node group YAML source file specified") unless @file
  raise("Node group YAML source file %s is not readable" % @file) unless File.readable?(@file)
  raise("No node group name specified") unless @group
  raise("No data group %s defined in the data file %s" % [@group, @file]) unless data.include?(@group)
  raise("Data group %s is not an array" % @group) unless data[@group].is_a?(Array)
  raise("Data group %s is empty" % @group) if data[@group].empty?
end