Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Puppet8x support #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions lib/puppet/util/trocla_helper.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
module Puppet::Util::TroclaHelper
def trocla(trocla_func,has_options,*args)
# Functions called from puppet manifests that look like this:
# lookup("foo", "bar")
# internally in puppet are invoked: func(["foo", "bar"])
#
# where as calling from templates should work like this:
# scope.function_lookup("foo", "bar")
#
# Therefore, declare this function with args '*args' to accept any number
# of arguments and deal with puppet's special calling mechanism now:
if args[0].is_a?(Array)
args = args[0]
end

key = args[0] || raise(Puppet::ParseError, "You need to pass at least a key as an argument!")
format = args[1] || 'plain'
options = args[2] || {}

if options.is_a?(String)
require 'yaml'
options = YAML.load(options)
end

r = has_options ? store.send(trocla_func, key, format, options) : store.send(trocla_func, key, format)
store.close
r
# Functions called from puppet manifests that look like this:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for the change in indentation?

# lookup("foo", "bar")
# internally in puppet are invoked: func(["foo", "bar"])
#
# where as calling from templates should work like this:
# scope.function_lookup("foo", "bar")
#
# Therefore, declare this function with args '*args' to accept any number
# of arguments and deal with puppet's special calling mechanism now:
if args[0].is_a?(Array)
args = args[0]
end

key = args[0] || raise(Puppet::ParseError, "You need to pass at least a key as an argument!")
format = args[1] || 'plain'
options = args[2] || {}

if options.is_a?(String)
require 'yaml'
options = YAML.load(options)
end

r = has_options ? store.send(trocla_func, key, format, options) : store.send(trocla_func, key, format)
store.close
r
end
module_function :trocla

Expand Down
10 changes: 6 additions & 4 deletions manifests/ca/params.pp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# input for a ca from trocla, so that you need only
#
# @param trocla_options
#
# trocla('some_ca','x509',$trocla::ca::params::ca_options)
class trocla::ca::params(
$trocla_options = {
class trocla::ca::params (
Hash $trocla_options = {
'profiles' => ['sysdomain_nc','x509veryverylong'],
'CN' => "automated-ca ${name} for ${::domain}",
'CN' => "automated-ca ${name} for ${facts['networking']['domain']}",
},
) {
$ca_options = merge($trocla_options,{ become_ca => true, render => { certonly => true }})
$ca_options = merge($trocla_options, { become_ca => true, render => { certonly => true } })
}
33 changes: 18 additions & 15 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#Options
# [*options*] Options for trocla. Default: empty hash.
# [*profiles*] Profiles for trocla. Default: empty hash.
# [*x509_profile_domain_constraint*]
# [*x509_profile_domain_constraints*]
# A profile for x509 name constraint that matches
# the own domain by default.
# This will add a profile for x509 certs with the
Expand All @@ -21,35 +21,38 @@
# encryption. Default: empty Hash
# [*manage_dependencies*] Whether to manage the dependencies or not.
# Default *true*
# [*edit_uid*] edit_uid
# Default: puppet
#
class trocla::config (
$options = {},
$profiles = {},
$x509_profile_domain_constraints = [$::domain],
$store = undef,
$store_options = {},
$encryption = undef,
$encryption_options = {},
$manage_dependencies = true,
$edit_uid = 'puppet',
Hash $options = {},
Hash $profiles = {},
Array $x509_profile_domain_constraints = [$facts['networking']['domain']],
Optional[String] $store = undef,
Hash $store_options = {},
Optional[String] $encryption = undef,
Hash $encryption_options = {},
Boolean $manage_dependencies = true,
String $edit_uid = 'puppet',
) {
include ::trocla::params
include trocla::params
if $manage_dependencies {
require ::trocla::master
require trocla::master
}

if empty($x509_profile_domain_constraints) {
$merged_profiles = $profiles
} else {
$default_profiles = {
"${trocla::params::sysdomain_profile_name}" => {
name_constraints => $x509_profile_domain_constraints
}
name_constraints => $x509_profile_domain_constraints,
},
}
$merged_profiles = merge($default_profiles,$profiles)
}

# Deploy default config file and link it for trocla cli lookup
file{
file {
"${settings::confdir}/troclarc.yaml":
content => template('trocla/troclarc.yaml.erb'),
owner => 'root',
Expand Down
22 changes: 13 additions & 9 deletions manifests/master.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
#
# This module manages the necessary things for trocla on a master.
#
# @param package_name
# @param provider
# @param source
#
class trocla::master (
$provider = 'default',
String $package_name = 'trocla',
Optional[String] $provider = undef,
Optional[String] $source = undef,
) {
package {'trocla':
package { 'trocla':
ensure => 'installed',
name => $package_name,
provider => $provider,
source => $source,
}

if $provider != 'default' {
Package['trocla']{
provider => $provider,
}
}
if $provider != 'gem' and $provider != 'puppetserver_gem' and $::osfamily == 'RedHat' {
Package['trocla']{
if $provider != 'gem' and $provider != 'puppetserver_gem' and $facts['os']['family'] == 'RedHat' {
Package['trocla'] {
name => 'rubygem-trocla'
}
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/master/hiera.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# manage trocla/hiera integration
class trocla::master::hiera {
package{'rubygem-hiera-backend-trocla':
package { 'rubygem-hiera-backend-trocla':
ensure => present,
}
}
12 changes: 12 additions & 0 deletions manifests/master/ree.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Class: trocla::master::ree
#
# This module manages the necessary things for trocla on a master for
# RubyEnterprise installation.
#
# [Remember: No empty lines between comments and class definition]
class trocla::master::ree {
require ruby_enterprise::gems::moneta
require ruby_enterprise::gems::highline

ruby_enterprise::gem { 'trocla': }
}
10 changes: 6 additions & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# a set of default params for various trocla usages
class trocla::params(
$sysdomain_profile_name = 'sysdomain_nc'
){

#
# @param sysdomain_profile_name
#
class trocla::params (
String $sysdomain_profile_name = 'sysdomain_nc'
) {
}
37 changes: 20 additions & 17 deletions manifests/yaml.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# This will install and configure trocla with the
# default yaml storage.
#
# [*data_file*] Where to store the passwords.
# Default: /var/lib/trocla/trocla_data.yaml
# This should be managed using the package.
# @param manage_data_dir
# @param data_file
# Where to store the passwords. Default: /var/lib/trocla/trocla_data.yaml. This should be managed using the package.
# @param edit_uid
#
class trocla::yaml (
$manage_data_dir = true,
$data_file = '/var/lib/trocla/trocla_data.yaml',
$edit_uid = 'puppet',
Boolean $manage_data_dir = true,
String $data_file = '/var/lib/trocla/trocla_data.yaml',
String $edit_uid = 'puppet',
) {
class { 'trocla::config':
edit_uid => $edit_uid,
Expand All @@ -23,19 +25,20 @@

if $manage_data_dir {
$data_dir = dirname($data_file)
Package<| title == 'trocla' |> -> file {
$data_dir:
ensure => directory,
owner => $edit_uid,
group => 0,
mode => '0600';
file { $data_dir:
ensure => directory,
owner => $edit_uid,
group => 0,
mode => '0600',
require => Package['trocla'];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea to use the collector is that the collector can also be empty since there might be cases where you do not have the package installed.

}
}
Package<| title == 'trocla' |> -> file {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here with the collector

file {
$data_file:
ensure => file,
owner => $edit_uid,
group => 0,
mode => '0600';
ensure => file,
owner => $edit_uid,
group => 0,
mode => '0600',
require => Package['trocla'];
}
}
2 changes: 1 addition & 1 deletion templates/troclarc.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
out << "#{indent}#{e[0]}:"
out << sort_pseudo_yaml(e[1],indent+' ')
elsif e[1].is_a?(Array)
out << (["#{indent}#{e[0]}:"]+e[1].collect{|e| " - #{e}" }).join("\n#{indent}")
out << (["#{indent}#{e[0]}:"]+e[1].collect{|e| "- #{e}" }).join("\n#{indent}")
else
out << "#{indent}#{e[0].is_a?(Symbol) ? ":#{e[0].to_s}" : e[0]}: #{e[1].is_a?(Symbol) ? ":#{e[1].to_s}" : e[1]}"
end
Expand Down