29 changes: 28 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,34 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not affect the functionality of the module.

## [v11.0.0](https://github.com/voxpupuli/puppet-rabbitmq/tree/v11.0.0) (2021-01-16)
## [v11.1.0](https://github.com/voxpupuli/puppet-rabbitmq/tree/v11.1.0) (2021-05-06)

[Full Changelog](https://github.com/voxpupuli/puppet-rabbitmq/compare/v11.0.0...v11.1.0)

**Implemented enhancements:**

- Compatibility with camptocamp/systemd 3.x [\#886](https://github.com/voxpupuli/puppet-rabbitmq/pull/886) ([TheMeier](https://github.com/TheMeier))
- camptocamp/systemd: Allow 3.x [\#884](https://github.com/voxpupuli/puppet-rabbitmq/pull/884) ([bastelfreak](https://github.com/bastelfreak))
- Add auto cluster configuration support [\#883](https://github.com/voxpupuli/puppet-rabbitmq/pull/883) ([fatpat](https://github.com/fatpat))
- puppet/archive: Allow 5.x [\#882](https://github.com/voxpupuli/puppet-rabbitmq/pull/882) ([bastelfreak](https://github.com/bastelfreak))
- Enable Puppet 7 support \(where applicable\) [\#881](https://github.com/voxpupuli/puppet-rabbitmq/pull/881) ([bastelfreak](https://github.com/bastelfreak))
- puppetlabs/stdlib: allow 7.x [\#880](https://github.com/voxpupuli/puppet-rabbitmq/pull/880) ([bastelfreak](https://github.com/bastelfreak))
- Add support for oom\_score\_adj [\#877](https://github.com/voxpupuli/puppet-rabbitmq/pull/877) ([jlutran](https://github.com/jlutran))

**Fixed bugs:**

- CLI Environment Fixes [\#876](https://github.com/voxpupuli/puppet-rabbitmq/pull/876) ([bishopbm1](https://github.com/bishopbm1))
- make sure the rabbitmq\_version method actually returns the version. [\#874](https://github.com/voxpupuli/puppet-rabbitmq/pull/874) ([TomRitserveldt](https://github.com/TomRitserveldt))

**Closed issues:**

- Auto Clustering of nodes should be enabled [\#792](https://github.com/voxpupuli/puppet-rabbitmq/issues/792)

**Merged pull requests:**

- Use mocked facts in tests [\#873](https://github.com/voxpupuli/puppet-rabbitmq/pull/873) ([ekohl](https://github.com/ekohl))

## [v11.0.0](https://github.com/voxpupuli/puppet-rabbitmq/tree/v11.0.0) (2021-01-17)

[Full Changelog](https://github.com/voxpupuli/puppet-rabbitmq/compare/v10.3.0...v11.0.0)

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"

group :test do
gem 'voxpupuli-test', '~> 2.1', :require => false
gem 'voxpupuli-test', '~> 2.2', :require => false
gem 'coveralls', :require => false
gem 'simplecov-console', :require => false
end
Expand Down
79 changes: 79 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ _Private Classes_
**Resource types**

* [`rabbitmq_binding`](#rabbitmq_binding): Native type for managing rabbitmq bindings rabbitmq_binding { 'binding 1': ensure => present, source => 'myexchange'
* [`rabbitmq_cluster`](#rabbitmq_cluster): Native type for managing rabbitmq cluster
* [`rabbitmq_erlang_cookie`](#rabbitmq_erlang_cookie): Type to manage the rabbitmq erlang cookie securely This is essentially a private type used by the rabbitmq::config class to manage the erlan
* [`rabbitmq_exchange`](#rabbitmq_exchange): Native type for managing rabbitmq exchanges
* [`rabbitmq_parameter`](#rabbitmq_parameter): Type for managing rabbitmq parameters
Expand Down Expand Up @@ -140,6 +141,10 @@ This will result in the following config appended to the config file:

```puppet
class { 'rabbitmq':
cluster => {
'name' => 'test_cluster',
'init_node' => 'hostname'
},
config_cluster => true,
cluster_nodes => ['rabbit1', 'rabbit2'],
cluster_node_type => 'ram',
Expand Down Expand Up @@ -189,6 +194,14 @@ rabbit_auth_backend_ldap].

Default value: `undef`

##### `cluster`

Data type: `Hash`

Join cluster and change name of cluster.

Default value: $rabbitmq::cluster

##### `cluster_node_type`

Data type: `Enum['ram', 'disc']`
Expand Down Expand Up @@ -375,6 +388,14 @@ Set rabbitmq file ulimit. Defaults to 16384. Only available on systems with `$::

Default value: 16384

##### `oom_score_adj`

Data type: `Integer[-1000, 1000]`

Set rabbitmq-server process OOM score. Defaults to 0.

Default value: 0

##### `heartbeat`

Data type: `Optional[Integer]`
Expand Down Expand Up @@ -1132,6 +1153,64 @@ The password to use to connect to rabbitmq

Default value: guest

### rabbitmq_cluster

Native type for managing rabbitmq cluster

#### Examples

##### Configure a cluster, rabbit_cluster

```puppet
rabbitmq_cluster { 'rabbit_cluster':
init_node => 'host1'
}
```

##### Optional parameter tags will set further rabbitmq tags like monitoring, policymaker, etc.

```puppet
To set the cluster name use cluster_name.
rabbitmq_cluster { 'rabbit_cluster':
init_node => 'host1',
node_disc_type => 'ram',
}
```

#### Properties

The following properties are available in the `rabbitmq_cluster` type.

##### `ensure`

Valid values: present, absent

The basic property that the resource should be in.

Default value: present

#### Parameters

The following parameters are available in the `rabbitmq_cluster` type.

##### `name`

namevar

The cluster name

##### `init_node`

Name of which cluster node to join.

##### `node_disc_type`

Valid values: %r{disc|ram}

Storage type of node, default disc.

Default value: disc

### rabbitmq_erlang_cookie

Type to manage the rabbitmq erlang cookie securely
Expand Down
1 change: 1 addition & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
rabbitmq::admin_enable: true
rabbitmq::management_enable: false
rabbitmq::use_config_file_for_plugins: false
rabbitmq::cluster: {}
rabbitmq::cluster_node_type: 'disc'
rabbitmq::cluster_nodes: []
rabbitmq::config: 'rabbitmq/rabbitmq.config.erb'
Expand Down
5 changes: 5 additions & 0 deletions examples/cluster/join_cluster_and_change_name.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This sets the cluster name to `test_cluster`
# If run on another host than host1, this will join the host1's cluster
rabbitmq_cluster { 'test_cluster':
init_node => 'host1',
}
15 changes: 15 additions & 0 deletions lib/facter/rabbitmq_clustername.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Facter.add(:rabbitmq_clustername) do
setcode do
if Facter::Util::Resolution.which('rabbitmqctl')
ret = nil
cluster_status = Facter::Core::Execution.execute('rabbitmqctl -q cluster_status 2>&1')
[%r!{cluster_name,<<"(\S+)">>}!, %r!^Cluster name: (\S+)$!].each do |r|
if (data = r.match(cluster_status))
ret = data[1]
break
end
end
end
ret
end
end
3 changes: 2 additions & 1 deletion lib/puppet/provider/rabbitmq_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.append_to_path(dir)

def self.home_tmp_command(name, path)
has_command name, path do
environment HOME: '/tmp'
environment HOME: '/tmp', LC_ALL: 'en_US.UTF-8'
end
end

Expand All @@ -40,6 +40,7 @@ def self.rabbitmq_version
output = rabbitmqctl('-q', 'status')
version = output.match(%r{RabbitMQ.*?([\d\.]+)})
@rabbitmq_version = version[1] if version
@rabbitmq_version
end

def self.rabbitmqctl_list(resource, *opts)
Expand Down
40 changes: 40 additions & 0 deletions lib/puppet/provider/rabbitmq_cluster/rabbitmqctl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmq_cli'))
Puppet::Type.type(:rabbitmq_cluster).provide(
:rabbitmqctl,
parent: Puppet::Provider::RabbitmqCli
) do
confine feature: :posix

def exists?
cluster_name == @resource[:name].to_s
end

def create
storage_type = @resource[:node_disc_type].to_s

init_node = @resource[:init_node].to_s.gsub(%r{^.*@}, '')

if [Facter.value(:hostname), Facter.value(:fqdn)].include? init_node
return rabbitmqctl('set_cluster_name', @resource[:name]) unless cluster_name == resource[:name].to_s
else
rabbitmqctl('stop_app')
rabbitmqctl('join_cluster', "rabbit@#{init_node}", "--#{storage_type}")
rabbitmqctl('start_app')
end
end

def destroy
rabbitmqctl('stop_app')
rabbitmqctl('reset')
rabbitmqctl('start_app')
end

def cluster_name
cluster_status = rabbitmqctl('-q', 'cluster_status')
[%r!{cluster_name,<<"(\S+)">>}!, %r!^Cluster name: (\S+)$!].each do |r|
if (data = r.match(cluster_status))
return data[1]
end
end
end
end
50 changes: 50 additions & 0 deletions lib/puppet/type/rabbitmq_cluster.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Puppet::Type.newtype(:rabbitmq_cluster) do
desc <<-DESC
Native type for managing rabbitmq cluster
@example Configure a cluster, rabbit_cluster
rabbitmq_cluster { 'rabbit_cluster':
init_node => 'host1'
}
@example Optional parameter tags will set further rabbitmq tags like monitoring, policymaker, etc.
To set the cluster name use cluster_name.
rabbitmq_cluster { 'rabbit_cluster':
init_node => 'host1',
node_disc_type => 'ram',
}
DESC

ensurable do
defaultto(:present)
newvalue(:present) do
provider.create
end
newvalue(:absent) do
provider.destroy
end
end

autorequire(:service) { 'rabbitmq-server' }

newparam(:name, namevar: true) do
desc 'The cluster name'
end

newparam(:init_node) do
desc 'Name of which cluster node to join.'
validate do |value|
resource.validate_init_node(value)
end
end

newparam(:node_disc_type) do
desc 'Storage type of node, default disc.'
newvalues(%r{disc|ram})
defaultto('disc')
end

def validate_init_node(value)
raise ArgumentError, 'init_node must be defined' if value.empty?
end
end
6 changes: 5 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
$auth_backends = $rabbitmq::auth_backends
$cluster_partition_handling = $rabbitmq::cluster_partition_handling
$file_limit = $rabbitmq::file_limit
$oom_score_adj = $rabbitmq::oom_score_adj
$collect_statistics_interval = $rabbitmq::collect_statistics_interval
$ipv6 = $rabbitmq::ipv6
$inetrc_config = $rabbitmq::inetrc_config
Expand Down Expand Up @@ -235,7 +236,10 @@
if $facts['systemd'] { # systemd fact provided by systemd module
systemd::service_limits { "${service_name}.service":
selinux_ignore_defaults => ($facts['os']['family'] == 'RedHat'),
limits => { 'LimitNOFILE' => $file_limit },
limits => {
'LimitNOFILE' => $file_limit,
'OOMScoreAdjust' => $oom_score_adj,
},
# The service will be notified when config changes
restart_service => false,
}
Expand Down
20 changes: 19 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
#
# @example Use RabbitMQ clustering facilities
# class { 'rabbitmq':
# cluster => {
# 'name' => 'test_cluster',
# 'init_node' => 'hostname'
# },
# config_cluster => true,
# cluster_nodes => ['rabbit1', 'rabbit2'],
# cluster_node_type => 'ram',
Expand All @@ -92,6 +96,7 @@
# An array specifying authorization/authentication backend to use. Single quotes should be placed around array entries,
# ex. `['{foo, baz}', 'baz']` Defaults to [rabbit_auth_backend_internal], and if using LDAP defaults to [rabbit_auth_backend_internal,
# rabbit_auth_backend_ldap].
# @param cluster Join cluster and change name of cluster.
# @param cluster_node_type
# Choose between disc and ram nodes.
# @param cluster_nodes
Expand Down Expand Up @@ -140,6 +145,8 @@
# to 'False' and set 'erlang_cookie'.
# @param file_limit
# Set rabbitmq file ulimit. Defaults to 16384. Only available on systems with `$::osfamily == 'Debian'` or `$::osfamily == 'RedHat'`.
# @param oom_score_adj
# Set rabbitmq-server process OOM score. Defaults to 0.
# @param heartbeat
# Set the heartbeat timeout interval, default is unset which uses the builtin server defaults of 60 seconds. Setting this
# @param inetrc_config
Expand Down Expand Up @@ -311,6 +318,7 @@
Boolean $admin_enable = true,
Boolean $management_enable = false,
Boolean $use_config_file_for_plugins = false,
Hash $cluster = $rabbitmq::cluster,
Enum['ram', 'disc'] $cluster_node_type = 'disc',
Array $cluster_nodes = [],
String $config = 'rabbitmq/rabbitmq.config.erb',
Expand Down Expand Up @@ -394,6 +402,7 @@
Boolean $wipe_db_on_cookie_change = false,
String $cluster_partition_handling = 'ignore',
Variant[Integer[-1],Enum['unlimited'],Pattern[/^(infinity|\d+(:(infinity|\d+))?)$/]] $file_limit = 16384,
Integer[-1000, 1000] $oom_score_adj = 0,
Hash $environment_variables = { 'LC_ALL' => 'en_US.UTF-8' },
Hash $config_variables = {},
Hash $config_kernel_variables = {},
Expand Down Expand Up @@ -522,6 +531,15 @@
Class['rabbitmq::install::rabbitmqadmin'] -> Rabbitmq_exchange<| |>
}

if $config_cluster and $cluster['name'] and $cluster['init_node'] {
create_resources('rabbitmq_cluster', {
$cluster['name'] => {
'init_node' => $cluster['init_node'],
'node_disc_type' => $cluster_node_type,
}
})
}

if ($service_restart) {
Class['rabbitmq::config'] ~> Class['rabbitmq::service']
}
Expand All @@ -532,5 +550,5 @@
-> Class['rabbitmq::management']

# Make sure the various providers have their requirements in place.
Class['rabbitmq::install'] -> Rabbitmq_plugin<| |>
Class['rabbitmq::install'] -> Rabbitmq_plugin<| |> -> Rabbitmq_cluster<| |>
}
3 changes: 1 addition & 2 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
hasrestart => true,
name => $service_name,
}

if $facts['systemd'] {
if $facts['systemd'] and defined(Class['systemd::systemctl::daemon_reload']) {
Class['systemd::systemctl::daemon_reload'] -> Service['rabbitmq-server']
}
}
Expand Down
Loading