OLD | NEW |
1 #!/usr/bin/env ruby | 1 #!/usr/bin/env ruby |
2 # This script is a node classifier for Puppet that operates on top of Hiera | 2 # This script is a node classifier for Puppet that operates on top of Hiera |
3 # and uses a custom hosts.yaml config to map host roles. | 3 # and uses a custom hosts.yaml config to map host roles. |
4 | 4 |
5 require 'getoptlong' | 5 require 'getoptlong' |
6 require 'hiera' | 6 require 'hiera' |
7 require 'socket' | 7 require 'socket' |
8 require 'yaml' | 8 require 'yaml' |
9 | 9 |
10 # Where to search for the Hiera configuration | 10 # Where to search for the Hiera configuration |
11 HIERA_CONFIG = ENV.fetch('PUPPET_HIERA_CONFIG', '/etc/puppet/hiera.yaml') | 11 HIERA_CONFIG = ENV.fetch('PUPPET_HIERA_CONFIG', '/etc/puppet/hiera.yaml') |
12 # Where to search for the Hosts configuration | 12 # Where to search for the Hosts configuration |
13 HOSTS_CONFIG = ENV.fetch('PUPPET_HOSTS_CONFIG', '/etc/puppet/infrastructure/hier
a/private/hosts.yaml') | 13 HOSTS_CONFIG = ENV.fetch('PUPPET_HOSTS_CONFIG', '/etc/puppet/infrastructure/modu
les/private/hiera/hosts.yaml') |
14 | 14 |
15 # For logging and usage hints | 15 # For logging and usage hints |
16 BASENAME = File.basename($0) | 16 BASENAME = File.basename($0) |
17 | 17 |
18 # There's no need for any options beside the commonly exepected ones yet | 18 # There's no need for any options beside the commonly exepected ones yet |
19 GetoptLong.new( | 19 GetoptLong.new( |
20 ['--help', '-h', GetoptLong::NO_ARGUMENT] | 20 ['--help', '-h', GetoptLong::NO_ARGUMENT] |
21 ).each do |opt, arg| | 21 ).each do |opt, arg| |
22 case opt | 22 case opt |
23 | 23 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 parameters = hiera.lookup('parameters', {}, scope, nil, :hash) | 81 parameters = hiera.lookup('parameters', {}, scope, nil, :hash) |
82 parameters['role'] = role | 82 parameters['role'] = role |
83 result = { 'classes' => classes, 'parameters' => parameters } | 83 result = { 'classes' => classes, 'parameters' => parameters } |
84 rescue Exception => error | 84 rescue Exception => error |
85 STDERR.puts "#{BASENAME}: #{error.message}: #{HIERA_CONFIG}" | 85 STDERR.puts "#{BASENAME}: #{error.message}: #{HIERA_CONFIG}" |
86 exit 1 | 86 exit 1 |
87 end | 87 end |
88 | 88 |
89 puts result.to_yaml | 89 puts result.to_yaml |
90 | 90 |
OLD | NEW |