- Drop use of module_data for now as it seems support for this was wrenched in <3.4.2
- Removed module data from base module - Enabled a couple of more terminus specific options in puppet.conf - A fewother small tweaks for testing
This commit is contained in:
parent
cf216f2c54
commit
35530aa715
|
@ -2,7 +2,6 @@
|
|||
classes:
|
||||
- base
|
||||
|
||||
|
||||
ldapclient::ldapcert: |
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIE7jCCA9agAwIBAgIJAKVPvcTSmTbFMA0GCSqGSIb3DQEBBQUAMIGqMQswCQYD
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
---
|
||||
|
||||
classes:
|
||||
- base
|
||||
- dnsclient
|
||||
- ldapclient
|
||||
- subversionclient
|
||||
- sudoers
|
||||
classes:
|
||||
- base
|
||||
|
||||
ldapclient::ldapclient_packages:
|
||||
- ldap-auth-client
|
||||
- ldap-utils
|
||||
- libldap-2.4-2
|
||||
|
||||
base::basepackages:
|
||||
- 'bash'
|
||||
- 'ca_root_nss-3.15.5'
|
||||
- 'git'
|
||||
- 'zsh-5.0.5'
|
||||
- 'apt-file'
|
||||
|
|
16
hiera.yaml
16
hiera.yaml
|
@ -4,20 +4,20 @@
|
|||
|
||||
|
||||
:backends:
|
||||
- module_data
|
||||
- yaml
|
||||
- eyaml
|
||||
|
||||
# The ASF specific variables below are created in facter with customfact module.
|
||||
:hierarchy:
|
||||
- "%{clientcert}"
|
||||
- "%{asf_osname}/%{asf_osrelease}"
|
||||
- "colo/%{asf_colo}"
|
||||
- "common"
|
||||
|
||||
:yaml:
|
||||
:datadir: /etc/puppet/data
|
||||
|
||||
:eyaml:
|
||||
:datadir: /etc/puppet/data
|
||||
|
||||
# The ASF specific variables below are created in facter with customfact module.
|
||||
:hierarchy:
|
||||
- "nodes/%{clientcert}"
|
||||
- "%{::asf_osname}/%{::asf_osrelease}"
|
||||
- "colo/%{asf_colo}"
|
||||
- "common"
|
||||
|
||||
:logger: console
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
hiera_include("classes")
|
||||
|
||||
include customfact
|
||||
|
||||
node default {
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
---
|
||||
|
||||
base::base_packages:
|
||||
- 'bash-4.3.0_1'
|
||||
- 'ca_root_nss-3.15.5'
|
||||
- 'git-1.9.0_1'
|
||||
- 'zsh-5.0.5'
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
:hierarchy:
|
||||
- "%{::asf_osname}/%{::asf_osrelease}"
|
||||
- "common"
|
|
@ -1,8 +0,0 @@
|
|||
---
|
||||
|
||||
base::base_packages:
|
||||
- 'bash'
|
||||
- 'ca_root_nss-3.15.5'
|
||||
- 'git'
|
||||
- 'zsh-5.0.5'
|
||||
- 'apt-file'
|
|
@ -1,12 +1,13 @@
|
|||
#/usr/local/etc/puppet/modules/base/manifests/init.pp
|
||||
|
||||
class base (
|
||||
$base_packages = [],
|
||||
$basepackages = hiera('base::basepackages'),
|
||||
$pkgprovider = '',
|
||||
) {
|
||||
|
||||
|
||||
package { $base_packages:
|
||||
package { $basepackages:
|
||||
ensure => installed,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
name 'ripienaar-module_data'
|
||||
version '0.0.3'
|
||||
description 'A hiera backend to allow the use of data while writing sharable modules'
|
||||
project_page 'https://github.com/ripienaar/puppet-module-data'
|
||||
license 'ASL 2.0'
|
||||
author 'R.I.Pienaar <rip@devco.net>'
|
|
@ -1,61 +0,0 @@
|
|||
What?
|
||||
=====
|
||||
|
||||
While hiera does a decent job of separating code and data for users
|
||||
it is quite difficult for module authors to use hiera to create reusable
|
||||
modules. This is because the puppet backend is optional and even when
|
||||
it is loaded the module author cannot influence the hierarchy.
|
||||
|
||||
With this commit we add a new module_data backend that loads data from
|
||||
within a module and allow the module author to set a hierarchy for this
|
||||
data.
|
||||
|
||||
The goal of this backend is to allow module authors to specify true
|
||||
module default data in their modules but still allow users to override
|
||||
the data using the standard method - especially useful with the puppet 3
|
||||
hiera integration.
|
||||
|
||||
This backend is always loaded as the least important tier in the
|
||||
hierarchy - unless a user choose to put it somewhere specific, but this
|
||||
backend will always be enabled.
|
||||
|
||||
Given a module layout:
|
||||
|
||||
your_module
|
||||
├── data
|
||||
│ ├── hiera.yaml
|
||||
│ └── osfamily
|
||||
│ ├── Debian.yaml
|
||||
│ └── RedHat.yaml
|
||||
└── manifests
|
||||
└── init.pp
|
||||
|
||||
The hiera.yaml is optional in this example it would be:
|
||||
|
||||
---
|
||||
:hierarchy:
|
||||
- osfamily/%{::osfamily}
|
||||
- common
|
||||
|
||||
But when no hiera.yaml exist in the module, the default would be:
|
||||
|
||||
---
|
||||
:hierarchy:
|
||||
- common
|
||||
|
||||
The data directory is then a standard Hiera data store.
|
||||
|
||||
Status?
|
||||
-------
|
||||
|
||||
This is but a first stab at turning my old pull request for ticket 16856
|
||||
into a standalone module that any > 3.0.0 Puppet user can depend on to
|
||||
get this essential feature.
|
||||
|
||||
Some more testing is needed, sanity checking for support versions etc so
|
||||
consider this a early feedback-saught release
|
||||
|
||||
Contact?
|
||||
--------
|
||||
|
||||
R.I.Pienaar / rip@devco.net / @ripienaar / http://devco.net
|
|
@ -1,91 +0,0 @@
|
|||
class Hiera
|
||||
module Backend
|
||||
class Module_data_backend
|
||||
def initialize(cache=nil)
|
||||
require 'yaml'
|
||||
require 'hiera/filecache'
|
||||
|
||||
Hiera.debug("Hiera Module Data backend starting")
|
||||
|
||||
@cache = cache || Filecache.new
|
||||
end
|
||||
|
||||
def load_module_config(module_name, environment)
|
||||
default_config = {:hierarchy => ["common"]}
|
||||
|
||||
if mod = Puppet::Module.find(module_name, environment)
|
||||
path = mod.path
|
||||
module_config = File.join(path, "data", "hiera.yaml")
|
||||
config = {}
|
||||
|
||||
if File.exist?(module_config)
|
||||
Hiera.debug("Reading config from %s file" % module_config)
|
||||
config = load_data(module_config)
|
||||
end
|
||||
|
||||
config["path"] = path
|
||||
|
||||
return default_config.merge(config)
|
||||
else
|
||||
return default_config
|
||||
end
|
||||
end
|
||||
|
||||
def load_data(path)
|
||||
return {} unless File.exist?(path)
|
||||
|
||||
@cache.read(path, Hash, {}) do |data|
|
||||
YAML.load(data)
|
||||
end
|
||||
end
|
||||
|
||||
def lookup(key, scope, order_override, resolution_type)
|
||||
answer = nil
|
||||
|
||||
Hiera.debug("Looking up %s in Module Data backend" % key)
|
||||
|
||||
unless scope["module_name"]
|
||||
Hiera.debug("Skipping Module Data backend as this does not look like a module")
|
||||
return answer
|
||||
end
|
||||
|
||||
config = load_module_config(scope["module_name"], scope["environment"])
|
||||
|
||||
unless config["path"]
|
||||
Hiera.debug("Could not find a path to the module '%s' in environment '%s'" % [scope["module_name"], scope["environment"]])
|
||||
return answer
|
||||
end
|
||||
|
||||
config[:hierarchy].each do |source|
|
||||
source = File.join(config["path"], "data", "%s.yaml" % Backend.parse_string(source, scope))
|
||||
|
||||
Hiera.debug("Looking for data in source %s" % source)
|
||||
data = load_data(source)
|
||||
|
||||
raise("Data loaded from %s should be a hash but got %s" % [source, data.class]) unless data.is_a?(Hash)
|
||||
|
||||
next if data.empty?
|
||||
next unless data.include?(key)
|
||||
|
||||
found = data[key]
|
||||
|
||||
case resolution_type
|
||||
when :array
|
||||
raise("Hiera type mismatch: expected Array or String and got %s" % found.class) unless [Array, String].include?(found.class)
|
||||
answer ||= []
|
||||
answer << Backend.parse_answer(found, scope)
|
||||
|
||||
when :hash
|
||||
raise("Hiera type mismatch: expected Hash and got %s" % found.class) unless found.is_a?(Hash)
|
||||
answer = Backend.parse_answer(found, scope).merge(answer || {})
|
||||
else
|
||||
answer = Backend.parse_answer(found, scope)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return answer
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,75 +0,0 @@
|
|||
require "hiera"
|
||||
require "hiera/config"
|
||||
require "hiera/scope"
|
||||
|
||||
begin
|
||||
require 'puppet/indirector/hiera'
|
||||
rescue LoadError => e
|
||||
begin
|
||||
require "puppet/indirector/code"
|
||||
rescue LoadError => e
|
||||
$stderr.puts "Couldn't require either of puppet/indirector/{hiera,code}!"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Hiera::Config
|
||||
class << self
|
||||
alias :old_load :load unless respond_to?(:old_load)
|
||||
|
||||
def load(source)
|
||||
old_load(source)
|
||||
|
||||
@config[:backends] << "module_data" unless @config[:backends].include?("module_data")
|
||||
|
||||
@config
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Puppet::DataBinding::Hiera < Puppet::Indirector::Code
|
||||
desc "Retrieve data using Hiera."
|
||||
|
||||
def initialize(*args)
|
||||
if ! Puppet.features.hiera?
|
||||
raise "Hiera terminus not supported without hiera library"
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
if defined?(::Psych::SyntaxError)
|
||||
DataBindingExceptions = [::StandardError, ::Psych::SyntaxError]
|
||||
else
|
||||
DataBindingExceptions = [::StandardError]
|
||||
end
|
||||
|
||||
def find(request)
|
||||
hiera.lookup(request.key, nil, Hiera::Scope.new(request.options[:variables]), nil, nil)
|
||||
rescue *DataBindingExceptions => detail
|
||||
raise Puppet::DataBinding::LookupError.new(detail.message, detail)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.hiera_config
|
||||
hiera_config = Puppet.settings[:hiera_config]
|
||||
config = {}
|
||||
|
||||
if File.exist?(hiera_config)
|
||||
config = Hiera::Config.load(hiera_config)
|
||||
else
|
||||
Puppet.warning "Config file #{hiera_config} not found, using Hiera defaults"
|
||||
end
|
||||
|
||||
config[:logger] = 'puppet'
|
||||
config
|
||||
end
|
||||
|
||||
def self.hiera
|
||||
@hiera ||= Hiera.new(:config => hiera_config)
|
||||
end
|
||||
|
||||
def hiera
|
||||
self.class.hiera
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"author": "R.I.Pienaar <rip@devco.net>",
|
||||
"description": "A hiera backend to allow the use of data while writing sharable modules",
|
||||
"source": "UNKNOWN",
|
||||
"checksums": {
|
||||
"README.md": "3c2b5884ad51ef786b8613dd8e147e2b",
|
||||
"Modulefile": "7cd4a28852f136be87acc5c71cc74a1f",
|
||||
"lib/puppet/indirector/data_binding/hiera.rb": "9a67f431134c49f86fa686b116718806",
|
||||
"lib/hiera/backend/module_data_backend.rb": "8f9da7dd8e7d02fb7beac72f187ad874"
|
||||
},
|
||||
"name": "ripienaar-module_data",
|
||||
"version": "0.0.3",
|
||||
"project_page": "https://github.com/ripienaar/puppet-module-data",
|
||||
"license": "ASL 2.0",
|
||||
"dependencies": [
|
||||
|
||||
],
|
||||
"summary": "UNKNOWN",
|
||||
"types": [
|
||||
|
||||
]
|
||||
}
|
|
@ -14,8 +14,8 @@ sslddir = /etc/puppet/ssl
|
|||
data_binding_terminus = hiera
|
||||
hiera_config = /etc/puppet/hiera.yaml
|
||||
#catalog_terminus = compiler
|
||||
#facts_terminus = yaml
|
||||
#inventory_terminus = yaml
|
||||
facts_terminus = yaml
|
||||
inventory_terminus = yaml
|
||||
#default_file_terminus = rest
|
||||
#httplog = /var/log/puppet/http.log
|
||||
#filetimeout = 15
|
||||
|
|
Loading…
Reference in New Issue