From 63ab4de799e32aefcb9c720a99d88b23d3c0f4d9 Mon Sep 17 00:00:00 2001 From: new23d Date: Thu, 1 May 2014 15:19:47 +0100 Subject: [PATCH] Initial check-in. --- mco/.gitignore | 4 ++ msi/.gitignore | 4 ++ opt/Facter_CEF.xml | 57 ++++++++++++++++++++++++++++ opt/facter_cef.bat | 16 ++++++++ opt/facter_cef.rb | 81 ++++++++++++++++++++++++++++++++++++++++ opt/service.bat | 91 +++++++++++++++++++++++++++++++++++++++++++++ wks/.gitignore | 4 ++ wxs/mcollective.wxs | 80 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 337 insertions(+) create mode 100644 mco/.gitignore create mode 100644 msi/.gitignore create mode 100644 opt/Facter_CEF.xml create mode 100644 opt/facter_cef.bat create mode 100644 opt/facter_cef.rb create mode 100644 opt/service.bat create mode 100644 wks/.gitignore create mode 100644 wxs/mcollective.wxs diff --git a/mco/.gitignore b/mco/.gitignore new file mode 100644 index 0000000..86d0cb2 --- /dev/null +++ b/mco/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/msi/.gitignore b/msi/.gitignore new file mode 100644 index 0000000..86d0cb2 --- /dev/null +++ b/msi/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/opt/Facter_CEF.xml b/opt/Facter_CEF.xml new file mode 100644 index 0000000..033af64 --- /dev/null +++ b/opt/Facter_CEF.xml @@ -0,0 +1,57 @@ + + + + 2014-04-15T00:00:00 + new23d + Facter Caching of Expensive Facts + + + + + PT10M + false + + 2014-01-01T00:00:00 + PT9M + true + + + PT9M + true + + + PT9M + true + + + + + S-1-5-18 + HighestAvailable + + + + IgnoreNew + false + true + true + true + false + + true + false + + true + true + false + false + false + PT0S + 8 + + + + "%ProgramFiles(x86)%\MCollective\opt\facter_cef.bat" + + + \ No newline at end of file diff --git a/opt/facter_cef.bat b/opt/facter_cef.bat new file mode 100644 index 0000000..78d08da --- /dev/null +++ b/opt/facter_cef.bat @@ -0,0 +1,16 @@ +@echo off +setlocal enabledelayedexpansion + +set var_puppet_key_name="HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Puppet Labs\Puppet" +set var_puppet_value_name="RememberedInstallDir" + +for /f "usebackq skip=1 tokens=1,2*" %%a in (`reg query %var_puppet_key_name% /v %var_puppet_value_name%`) do (set var_puppet_base_dir=%%c) + +set var_mcollective_base_dir=%ProgramFiles(x86)%\MCollective\ +set var_mcollective_etc_dir=%ProgramData%\MCollective\etc\ + +set var_programfilesx86_dir=%ProgramFiles(x86)% + +call "%var_puppet_base_dir%bin\environment.bat" + +"%var_puppet_base_dir%sys\ruby\bin\ruby.exe" -I"%var_mcollective_base_dir%lib;%var_puppet_base_dir%puppet\lib;%var_puppet_base_dir%facter\lib;%var_puppet_base_dir%hiera\lib;" -- "%var_mcollective_base_dir%opt\facter_cef.rb" \ No newline at end of file diff --git a/opt/facter_cef.rb b/opt/facter_cef.rb new file mode 100644 index 0000000..5232800 --- /dev/null +++ b/opt/facter_cef.rb @@ -0,0 +1,81 @@ +## basic config start + +var_cached_facts_file = ENV['ProgramData'] + '/PuppetLabs/facter/facts.d/facter_cef.yaml' + +var_expensive_facts_regex = [ + 'network_.*', + 'interfaces', + 'macaddress_.*', + 'netmask_.*', + 'ipaddress6_.*', + 'mtu_.*', + 'ipaddress_.*', + 'ipaddress', + 'ipaddress6', + 'netmask', + 'macaddress' +] + +## basic config end + +## advanced config start + +var_facter_cmd = 'facter --no-external-dir --puppet --yaml --timing' + +## advanced config end + +## processing start +require 'yaml' +require 'open3' +require 'tempfile' + +var_stdin, var_stdout, var_stderr = Open3.popen3(var_facter_cmd) + +var_timing_data = Array.new +var_facter_data = String.new +var_cache = Hash.new + +# ugly loop to split timing and facter yaml data into separate variables +var_datatype_yaml_flag = false + +var_stdout.each do |var_line| + if var_datatype_yaml_flag == true + var_facter_data += var_line + else + if var_line != "--- \n" + var_timing_data.push(var_line) + else + var_datatype_yaml_flag = true + var_facter_data += var_line + end + end +end + +# the rest does get loaded up as valid yaml! +var_facter_data = YAML.load(var_facter_data) + +# in the timing data, look for matches of the expensive facts +var_timing_data.each do |var_line| + var_expensive_facts_regex.each do |var_regex| + if var_match = Regexp.new('(' + var_regex + '): ').match(var_line) + if var_facter_data[var_match[1]] + # if the fact is found in the yaml data as well, remember the value + var_cache[var_match[1]] = var_facter_data[var_match[1]] + else + # if not, assign it a non null value so that facter doesn't try and look it up. + # will think it has a value. + var_cache[var_match[1]] = 'UNKNOWN' + end + end + end +end + +var_file_handle = Tempfile.new('facter_cef_') + +var_file_handle.write(var_cache.to_yaml) +var_file_handle.close + +# atomic write +File.rename(var_file_handle.path, var_cached_facts_file) + +## processing end diff --git a/opt/service.bat b/opt/service.bat new file mode 100644 index 0000000..cc5005b --- /dev/null +++ b/opt/service.bat @@ -0,0 +1,91 @@ +@echo off +setlocal enabledelayedexpansion + +set var_puppet_key_name="HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Puppet Labs\Puppet" +set var_puppet_value_name="RememberedInstallDir" + +for /f "usebackq skip=1 tokens=1,2*" %%a in (`reg query %var_puppet_key_name% /v %var_puppet_value_name%`) do (set var_puppet_base_dir=%%c) + +set var_mcollective_base_dir=%ProgramFiles(x86)%\MCollective\ +set var_mcollective_etc_dir=%ProgramData%\MCollective\etc\ + +set var_programfilesx86_dir=%ProgramFiles(x86)% + +if not exist %ProgramData%\MCollective\etc\server.cfg ( +echo ^ +main_collective = mcollective^ + +#collectives = mcollective,gotham_collective^ + +libdir = !var_programfilesx86_dir!\MCollective\plugins^ + +logfile = %ProgramData%\MCollective\var\log\server.log^ + +loglevel = debug^ + +daemonize = 1^ + +^ + +securityprovider = psk^ + +plugin.psk = pass%RANDOM%word^ + +^ + +connector = rabbitmq^ + +direct_addressing = 1^ + +plugin.rabbitmq.vhost = mcollective^ + +^ + +plugin.rabbitmq.pool.1.host = rabbitmq.example.com^ + +plugin.rabbitmq.pool.1.user = joe^ + +plugin.rabbitmq.pool.1.password = pass%RANDOM%word^ + +plugin.rabbitmq.pool.1.port = 61613^ + +^ + +plugin.rabbitmq.pool.size = 1^ + +^ + +factsource = facter^ + +plugin.facter.facterlib = %ProgramData%\PuppetLabs\puppet\var\lib\facter^ + +^ + +#identity = %COMPUTERNAME%.example.com^ + +^ + +#registerinterval = 600^ + +#registration = agentlist^ + +#registration_collective = mcollective^ + +^ + +rpcaudit = 1^ + +rpcauditprovider = logfile^ + +plugin.rpcaudit.logfile = %ProgramData%\MCollective\var\log\audit.log^ + +^ + +classesfile = %ProgramData%\PuppetLabs\puppet\var\state\classes.txt^ + +> %ProgramData%\MCollective\etc\server.cfg +) + +call "%var_puppet_base_dir%bin\environment.bat" + +"%var_puppet_base_dir%sys\ruby\bin\ruby.exe" -I"%var_mcollective_base_dir%lib;%var_puppet_base_dir%puppet\lib;%var_puppet_base_dir%facter\lib;%var_puppet_base_dir%hiera\lib;" -- "%var_mcollective_base_dir%bin\mcollectived" --config "%var_mcollective_etc_dir%server.cfg" \ No newline at end of file diff --git a/wks/.gitignore b/wks/.gitignore new file mode 100644 index 0000000..86d0cb2 --- /dev/null +++ b/wks/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/wxs/mcollective.wxs b/wxs/mcollective.wxs new file mode 100644 index 0000000..3d0eec4 --- /dev/null +++ b/wxs/mcollective.wxs @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + PUPPETLABSINSTALLED + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (NOT Installed) + + REMOVE="ALL" + + + + + + + + + + + + \ No newline at end of file