From 1175c445e4c94958d48f6b2dcbf13224e76534a9 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Sat, 6 May 2017 09:03:54 +0100 Subject: [PATCH] Instance defined type * Move the config logic into a defined type * This will allow us to have multiple instances of redis on one machine in the future --- manifests/config.pp | 117 +------------------------ manifests/init.pp | 2 + manifests/instance_config.pp | 156 ++++++++++++++++++++++++++++++++++ manifests/params.pp | 1 + spec/defines/instance_spec.rb | 37 ++++++++ 5 files changed, 198 insertions(+), 115 deletions(-) create mode 100644 manifests/instance_config.pp create mode 100644 spec/defines/instance_spec.rb diff --git a/manifests/config.pp b/manifests/config.pp index 89ada497..215c7354 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -3,128 +3,15 @@ # This class provides configuration for Redis. # class redis::config { - $activerehashing = $::redis::activerehashing - $aof_load_truncated = $::redis::aof_load_truncated - $aof_rewrite_incremental_fsync = $::redis::aof_rewrite_incremental_fsync - $appendfilename = $::redis::appendfilename - $appendfsync = $::redis::appendfsync - $appendonly = $::redis::appendonly - $auto_aof_rewrite_min_size = $::redis::auto_aof_rewrite_min_size - $auto_aof_rewrite_percentage = $::redis::auto_aof_rewrite_percentage - $bind = $::redis::bind - $cluster_config_file = $::redis::cluster_config_file - $cluster_enabled = $::redis::cluster_enabled - $cluster_node_timeout = $::redis::cluster_node_timeout - $daemonize = $::redis::daemonize - $databases = $::redis::databases - $dbfilename = $::redis::dbfilename - $extra_config_file = $::redis::extra_config_file - $hash_max_ziplist_entries = $::redis::hash_max_ziplist_entries - $hash_max_ziplist_value = $::redis::hash_max_ziplist_value - $hll_sparse_max_bytes = $::redis::hll_sparse_max_bytes - $hz = $::redis::hz - $latency_monitor_threshold = $::redis::latency_monitor_threshold - $list_max_ziplist_entries = $::redis::list_max_ziplist_entries - $list_max_ziplist_value = $::redis::list_max_ziplist_value - $log_file = $::redis::log_file - $log_level = $::redis::log_level - $masterauth = $::redis::masterauth - $maxclients = $::redis::maxclients - $maxmemory = $::redis::maxmemory - $maxmemory_policy = $::redis::maxmemory_policy - $maxmemory_samples = $::redis::maxmemory_samples - $min_slaves_max_lag = $::redis::min_slaves_max_lag - $min_slaves_to_write = $::redis::min_slaves_to_write - $minimum_version = $::redis::minimum_version - $no_appendfsync_on_rewrite = $::redis::no_appendfsync_on_rewrite - $notify_keyspace_events = $::redis::notify_keyspace_events - $pid_file = $::redis::pid_file - $port = $::redis::port - $rdbcompression = $::redis::rdbcompression - $repl_backlog_size = $::redis::repl_backlog_size - $repl_backlog_ttl = $::redis::repl_backlog_ttl - $repl_disable_tcp_nodelay = $::redis::repl_disable_tcp_nodelay - $repl_ping_slave_period = $::redis::repl_ping_slave_period - $repl_timeout = $::redis::repl_timeout - $requirepass = $::redis::requirepass - $save_db_to_disk = $::redis::save_db_to_disk - $save_db_to_disk_interval = $::redis::save_db_to_disk_interval - $set_max_intset_entries = $::redis::set_max_intset_entries - $slave_priority = $::redis::slave_priority - $slave_read_only = $::redis::slave_read_only - $slave_serve_stale_data = $::redis::slave_serve_stale_data - $slaveof = $::redis::slaveof - $slowlog_log_slower_than = $::redis::slowlog_log_slower_than - $slowlog_max_len = $::redis::slowlog_max_len - $stop_writes_on_bgsave_error = $::redis::stop_writes_on_bgsave_error - $syslog_enabled = $::redis::syslog_enabled - $syslog_facility = $::redis::syslog_facility - $tcp_backlog = $::redis::tcp_backlog - $tcp_keepalive = $::redis::tcp_keepalive - $timeout = $::redis::timeout - $unixsocket = $::redis::unixsocket - $unixsocketperm = $::redis::unixsocketperm - $workdir = $::redis::workdir - $zset_max_ziplist_entries = $::redis::zset_max_ziplist_entries - $zset_max_ziplist_value = $::redis::zset_max_ziplist_value - File { - owner => $::redis::config_owner, - group => $::redis::config_group, - mode => $::redis::config_file_mode, - } - - file { $::redis::config_dir: - ensure => directory, - mode => $::redis::config_dir_mode, - } - - file {$::redis::config_file_orig: - ensure => file, - } - - $redis_version_real = pick(getvar_emptystring('redis_server_version'), $minimum_version) - - if ($redis_version_real and $::redis::conf_template == 'redis/redis.conf.erb') { - case $redis_version_real { - /^2.4./: { - File[$::redis::config_file_orig] { content => template('redis/redis.conf.2.4.10.erb') } - } - /^2.8./: { - File[$::redis::config_file_orig] { content => template('redis/redis.conf.2.8.erb') } - } - default: { - File[$::redis::config_file_orig] { content => template($::redis::conf_template) } - } - } - } else { - File[$::redis::config_file_orig] { content => template($::redis::conf_template) } - } - - file {$::redis::log_dir: - ensure => directory, - group => $::redis::service_group, - mode => $::redis::log_dir_mode, - owner => $::redis::service_user, - } - - file {$::redis::workdir: - ensure => directory, - group => $::redis::service_group, - mode => $::redis::workdir_mode, - owner => $::redis::service_user, + if $::redis::default_install { + redis::instance_config {'default':} } if $::redis::ulimit { contain ::redis::ulimit } - exec {"cp -p ${::redis::config_file_orig} ${::redis::config_file}": - path => '/usr/bin:/bin', - subscribe => File[$::redis::config_file_orig], - refreshonly => true; - } - # Adjust /etc/default/redis-server on Debian systems case $::osfamily { 'Debian': { diff --git a/manifests/init.pp b/manifests/init.pp index f9d636ac..6641460d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -27,6 +27,7 @@ # @param [String] config_owner Adjust filesystem owner for config files. # @param [String] conf_template Define which template to use. # @param [String] daemonize Have Redis run as a daemon. +# @param [String] default_install Configure a default install of redis # @param [String] databases Set the number of databases. # @param [String] dbfilename The filename where to dump the DB # @param [String] extra_config_file Description @@ -152,6 +153,7 @@ $config_owner = $::redis::params::config_owner, $daemonize = $::redis::params::daemonize, $databases = $::redis::params::databases, + $default_install = $::redis::params::default_install, $dbfilename = $::redis::params::dbfilename, $extra_config_file = $::redis::params::extra_config_file, $hash_max_ziplist_entries = $::redis::params::hash_max_ziplist_entries, diff --git a/manifests/instance_config.pp b/manifests/instance_config.pp new file mode 100644 index 00000000..c09f251d --- /dev/null +++ b/manifests/instance_config.pp @@ -0,0 +1,156 @@ +# redis::instance_config +# +# This is an defined type to allow the configuration of +# multiple redis instances on one machine without conflicts +# +# @summary Allows the configuration of multiple redis configurations on one machine +# +# @example +# redis::instance_config {'6380': +# port => '6380', +# } +# +# @param first The first parameter for this class +# @param second The second paramter for this class +define redis::instance_config( + $activerehashing = $::redis::activerehashing, + $aof_load_truncated = $::redis::aof_load_truncated, + $aof_rewrite_incremental_fsync = $::redis::aof_rewrite_incremental_fsync, + $appendfilename = $::redis::appendfilename, + $appendfsync = $::redis::appendfsync, + $appendonly = $::redis::appendonly, + $auto_aof_rewrite_min_size = $::redis::auto_aof_rewrite_min_size, + $auto_aof_rewrite_percentage = $::redis::auto_aof_rewrite_percentage, + $bind = $::redis::bind, + $conf_template = $::redis::conf_template, + $config_dir = $::redis::config_dir, + $config_dir_mode = $::redis::config_dir_mode, + $config_file = $::redis::config_file, + $config_file_mode = $::redis::config_file_mode, + $config_file_orig = $::redis::config_file_orig, + $config_group = $::redis::config_group, + $config_owner = $::redis::config_owner, + $daemonize = $::redis::daemonize, + $databases = $::redis::databases, + $dbfilename = $::redis::dbfilename, + $extra_config_file = $::redis::extra_config_file, + $hash_max_ziplist_entries = $::redis::hash_max_ziplist_entries, + $hash_max_ziplist_value = $::redis::hash_max_ziplist_value, + $hll_sparse_max_bytes = $::redis::hll_sparse_max_bytes, + $hz = $::redis::hz, + $latency_monitor_threshold = $::redis::latency_monitor_threshold, + $list_max_ziplist_entries = $::redis::list_max_ziplist_entries, + $list_max_ziplist_value = $::redis::list_max_ziplist_value, + $log_file = $::redis::log_file, + $log_level = $::redis::log_level, + $minimum_version = $::redis::minimum_version, + $masterauth = $::redis::masterauth, + $maxclients = $::redis::maxclients, + $maxmemory = $::redis::maxmemory, + $maxmemory_policy = $::redis::maxmemory_policy, + $maxmemory_samples = $::redis::maxmemory_samples, + $min_slaves_max_lag = $::redis::min_slaves_max_lag, + $min_slaves_to_write = $::redis::min_slaves_to_write, + $no_appendfsync_on_rewrite = $::redis::no_appendfsync_on_rewrite, + $notify_keyspace_events = $::redis::notify_keyspace_events, + $managed_by_cluster_manager = $::redis::managed_by_cluster_manager, + $pid_file = $::redis::pid_file, + $port = $::redis::port, + $rdbcompression = $::redis::rdbcompression, + $repl_backlog_size = $::redis::repl_backlog_size, + $repl_backlog_ttl = $::redis::repl_backlog_ttl, + $repl_disable_tcp_nodelay = $::redis::repl_disable_tcp_nodelay, + $repl_ping_slave_period = $::redis::repl_ping_slave_period, + $repl_timeout = $::redis::repl_timeout, + $requirepass = $::redis::requirepass, + $save_db_to_disk = $::redis::save_db_to_disk, + $save_db_to_disk_interval = $::redis::save_db_to_disk_interval, + $service_user = $::redis::service_user, + $set_max_intset_entries = $::redis::set_max_intset_entries, + $slave_priority = $::redis::slave_priority, + $slave_read_only = $::redis::slave_read_only, + $slave_serve_stale_data = $::redis::slave_serve_stale_data, + $slaveof = $::redis::slaveof, + $slowlog_log_slower_than = $::redis::slowlog_log_slower_than, + $slowlog_max_len = $::redis::slowlog_max_len, + $stop_writes_on_bgsave_error = $::redis::stop_writes_on_bgsave_error, + $syslog_enabled = $::redis::syslog_enabled, + $syslog_facility = $::redis::syslog_facility, + $tcp_backlog = $::redis::tcp_backlog, + $tcp_keepalive = $::redis::tcp_keepalive, + $timeout = $::redis::timeout, + $unixsocket = $::redis::unixsocket, + $unixsocketperm = $::redis::unixsocketperm, + $ulimit = $::redis::ulimit, + $zset_max_ziplist_entries = $::redis::zset_max_ziplist_entries, + $zset_max_ziplist_value = $::redis::zset_max_ziplist_value, + $cluster_enabled = $::redis::cluster_enabled, + $cluster_config_file = $::redis::cluster_config_file, + $cluster_node_timeout = $::redis::cluster_node_timeout, + $workdir = $::redis::workdir, +) { + + if $title == 'default' { + $redis_config_extension = '' + } else { + $redis_config_extension = ".${title}" + } + + File { + owner => $::redis::config_owner, + group => $::redis::config_group, + mode => $::redis::config_file_mode, + } + + file { $::redis::config_dir: + ensure => directory, + mode => $::redis::config_dir_mode, + } + + file {$::redis::log_dir: + ensure => directory, + group => $::redis::service_group, + mode => $::redis::log_dir_mode, + owner => $::redis::service_user, + } + + file {$::redis::workdir: + ensure => directory, + group => $::redis::service_group, + mode => $::redis::workdir_mode, + owner => $::redis::service_user, + } + + $redis_file_name_orig = "${::redis::config_file_orig}${redis_config_extension}" + $redis_file_name = "${::redis::config_file}${redis_config_extension}" + + file {$redis_file_name_orig: + ensure => file, + } + + $redis_version_real = pick(getvar_emptystring('redis_server_version'), $minimum_version) + + if ($redis_version_real and $::redis::conf_template == 'redis/redis.conf.erb') { + case $redis_version_real { + /^2.4./: { + File[$redis_file_name_orig] { content => template('redis/redis.conf.2.4.10.erb') } + } + /^2.8./: { + File[$redis_file_name_orig] { content => template('redis/redis.conf.2.8.erb') } + } + default: { + File[$redis_file_name_orig] { content => template($::redis::conf_template) } + } + } + } else { + File[$redis_file_name_orig] { content => template($::redis::conf_template) } + } + + exec {"cp -p ${redis_file_name_orig} ${redis_file_name}": + path => '/usr/bin:/bin', + subscribe => File[$redis_file_name_orig], + refreshonly => true; + } + + +} diff --git a/manifests/params.pp b/manifests/params.pp index 06ad2bc0..a4fd4a5e 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -19,6 +19,7 @@ $auto_aof_rewrite_percentage = 100 $bind = '127.0.0.1' $conf_template = 'redis/redis.conf.erb' + $default_install = true $databases = 16 $dbfilename = 'dump.rdb' $extra_config_file = undef diff --git a/spec/defines/instance_spec.rb b/spec/defines/instance_spec.rb new file mode 100644 index 00000000..7493a3f4 --- /dev/null +++ b/spec/defines/instance_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe 'redis::instance_config', :type => :define do + let :pre_condition do + 'class { "redis": + default_install => false, + }' + end + let :title do + 'redis2' + end + let :default_params do + { + + } + end + describe 'os-dependent items' do + context "on RedHat based systems" do + let :default_facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :operatingsystemmajrelease => '6', + :concat_basedir => '/dne', + :operatingsystem => 'RedHat', + :id => 'root', + :kernel => 'Linux', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + :is_pe => false, + } + end + let :params do default_params end + let :facts do default_facts end + it { should contain_file('/etc/redis.conf.puppet.redis2').with('content' => /^hash-max-zipmap-entries/) } + end + end +end