Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: hiera/puppet_node_classifier.rb

Issue 29366882: Issue 3574 - Refactor Puppet class base into class adblockplus (Closed)
Patch Set: For comment 6 Created Dec. 6, 2016, 11:42 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Vagrantfile ('k') | modules/adblockplus/manifests/init.pp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/ruby 1 #!/usr/bin/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
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #{BASENAME}: unknown option: #{ARGV[0]} 57 #{BASENAME}: unknown option: #{ARGV[0]}
58 #{BASENAME}: try #{BASENAME} --help 58 #{BASENAME}: try #{BASENAME} --help
59 END 59 END
60 exit 1 60 exit 1
61 end 61 end
62 62
63 # Extract the server -> hostname -> role information from the hosts 63 # Extract the server -> hostname -> role information from the hosts
64 # configuration file: 64 # configuration file:
65 begin 65 begin
66 config = YAML.load_file(HOSTS_CONFIG) 66 config = YAML.load_file(HOSTS_CONFIG)
67 servers = config.fetch("servers", {}) 67 servers = config.fetch("adblockplus::hosts", {})
68 host = servers.fetch(hostname, {}) 68 host = servers.fetch(hostname, {})
69 role = host.fetch("role", "default") 69 role = host.fetch("role", "default")
70 rescue Exception => error 70 rescue Exception => error
71 STDERR.puts "#{BASENAME}: #{error.message}: #{HOSTS_CONFIG}" 71 STDERR.puts "#{BASENAME}: #{error.message}: #{HOSTS_CONFIG}"
72 exit 1 72 exit 1
73 end 73 end
74 74
75 # Map Hiera data into the structure Puppet expects an ENC to generate (see 75 # Map Hiera data into the structure Puppet expects an ENC to generate (see
76 # https://docs.puppetlabs.com/guides/external_nodes.html for more info): 76 # https://docs.puppetlabs.com/guides/external_nodes.html for more info):
77 begin 77 begin
78 hiera = Hiera.new(:config => HIERA_CONFIG) 78 hiera = Hiera.new(:config => HIERA_CONFIG)
79 scope = {'::hostname' => hostname, '::role' => role} 79 scope = {'::hostname' => hostname, '::role' => role}
80 classes = hiera.lookup('classes', {}, scope, nil, :hash) 80 classes = hiera.lookup('classes', {}, scope, nil, :hash)
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
OLDNEW
« no previous file with comments | « Vagrantfile ('k') | modules/adblockplus/manifests/init.pp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld