20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,23 @@ matrix:
env: PUPPET_INSTALL_VERSION="1.5.2" PUPPET_INSTALL_TYPE=agent BEAKER_set="ubuntu-1404-docker"
script: bundle exec rake acceptance
bundler_args: --without development
- sudo: required
rvm: '2.4.0'
env: PUPPET_VERSION="~> 4.0" CHECK=build DEPLOY_TO_FORGE=yes
script: bundle exec rake build
bundler_args: --without development
branches:
only:
- master
- /^v\d/
deploy:
provider: puppetforge
user: arioch
password:
secure: "GKs0F12bYL2YuN717PzplXvaxvFg8aHT14e7moWzkeoQGXNbZ4JOu7JmsJjWMyPH/mmGDLM3ugQMa8aIC/iM1OronLmc5qERrlQaOZ8L6ytrfqJ0Uo3N8mmqy0MinINOCT0yPjxp/CHxUxg6R+NrZApYru66UN2AsHvFtoa2TZ0="
on:
tags: true
# all_branches is required to use tags
all_branches: true
# Only publish the build marked with "DEPLOY_TO_FORGE"
condition: "$DEPLOY_TO_FORGE = yes"
103 changes: 89 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,99 @@
# Change Log

## [Unreleased](https://github.com/arioch/puppet-redis/tree/HEAD)

[Full Changelog](https://github.com/arioch/puppet-redis/compare/v3.1.0...HEAD)

## [v3.1.0](https://github.com/arioch/puppet-redis/tree/v3.1.0) (2017-05-11)

[Full Changelog](https://github.com/arioch/puppet-redis/compare/3.0.0...v3.1.0)

**Implemented enhancements:**

- Please cut a release [\#201](https://github.com/arioch/puppet-redis/issues/201)

**Fixed bugs:**

- Sort problem in v1.2.4 template [\#195](https://github.com/arioch/puppet-redis/issues/195)

**Merged pull requests:**

- Add an optional third parameter to redisget\(\) to specify a default value [\#209](https://github.com/arioch/puppet-redis/pull/209) ([petems](https://github.com/petems))
- Updates docs for puppet functions [\#208](https://github.com/arioch/puppet-redis/pull/208) ([petems](https://github.com/petems))
- Add switch to manage File\[/var/run/redis\] [\#204](https://github.com/arioch/puppet-redis/pull/204) ([petems](https://github.com/petems))
- Ignore selinux default context for /etc/systemd/system/redis.service.d [\#202](https://github.com/arioch/puppet-redis/pull/202) ([amoralej](https://github.com/amoralej))
- Make TravisCI push to the Forge [\#191](https://github.com/arioch/puppet-redis/pull/191) ([arioch](https://github.com/arioch))

## [v3.0.0](https://github.com/arioch/puppet-redis/tree/v3.0.0) (2017-05-11)
[Full Changelog](https://github.com/arioch/puppet-redis/compare/1.2.4...v3.0.0)

**Implemented enhancements:**

- Ubuntu 16.04 support? [\#146](https://github.com/arioch/puppet-redis/issues/146)
- \[Whishlist\] Extend ulimit parameter to support limits.conf and systemd [\#130](https://github.com/arioch/puppet-redis/issues/130)
- Add overcommit.pp to deal with `Can't save in background: fork: Cannot allocate memory` ? [\#105](https://github.com/arioch/puppet-redis/issues/105)

**Fixed bugs:**

- The fix for issue \#192 broke service\_managed false [\#197](https://github.com/arioch/puppet-redis/issues/197)
- Ubuntu 16.04 changed sentinel config filename [\#175](https://github.com/arioch/puppet-redis/issues/175)
- sentinel support broken? [\#166](https://github.com/arioch/puppet-redis/issues/166)
- Ownership problem with Ubuntu redis-server [\#150](https://github.com/arioch/puppet-redis/issues/150)
- Parameters not valid for older Redis in config [\#111](https://github.com/arioch/puppet-redis/issues/111)

**Merged pull requests:**

- Update sort to specify key [\#199](https://github.com/arioch/puppet-redis/pull/199) ([petems](https://github.com/petems))
- Adds tests for when Redis service is unmanaged [\#198](https://github.com/arioch/puppet-redis/pull/198) ([petems](https://github.com/petems))
- Changing Travis back to Trusty [\#194](https://github.com/arioch/puppet-redis/pull/194) ([petems](https://github.com/petems))
- Remove service notification [\#193](https://github.com/arioch/puppet-redis/pull/193) ([petems](https://github.com/petems))
- Improves ulimit configuration [\#192](https://github.com/arioch/puppet-redis/pull/192) ([petems](https://github.com/petems))
- Updates metadata supported versions [\#190](https://github.com/arioch/puppet-redis/pull/190) ([petems](https://github.com/petems))
- Adds tests for Ubuntu 1404 and Trusty package [\#189](https://github.com/arioch/puppet-redis/pull/189) ([petems](https://github.com/petems))
- Adds redis::administration class [\#188](https://github.com/arioch/puppet-redis/pull/188) ([petems](https://github.com/petems))
- Adds logic for managing redis-sentinel package [\#187](https://github.com/arioch/puppet-redis/pull/187) ([petems](https://github.com/petems))
- Bump to version 3.0.0 [\#186](https://github.com/arioch/puppet-redis/pull/186) ([petems](https://github.com/petems))
- Moves location of redis-sentinel file [\#184](https://github.com/arioch/puppet-redis/pull/184) ([petems](https://github.com/petems))
- \(testing\) Simplify command run by TravisCI [\#183](https://github.com/arioch/puppet-redis/pull/183) ([ghoneycutt](https://github.com/ghoneycutt))
- Style [\#182](https://github.com/arioch/puppet-redis/pull/182) ([ghoneycutt](https://github.com/ghoneycutt))
- Adds acceptance tests for the redisget\(\) function [\#181](https://github.com/arioch/puppet-redis/pull/181) ([petems](https://github.com/petems))
- Add redisget\(\) [\#179](https://github.com/arioch/puppet-redis/pull/179) ([ghoneycutt](https://github.com/ghoneycutt))
- Fixes ordering of Apt repos [\#178](https://github.com/arioch/puppet-redis/pull/178) ([petems](https://github.com/petems))
- Add 2.4.10 config file for CentOS 6 [\#177](https://github.com/arioch/puppet-redis/pull/177) ([petems](https://github.com/petems))
- Refactoring common code patterns [\#174](https://github.com/arioch/puppet-redis/pull/174) ([petems](https://github.com/petems))
- Changes permission on /var/run/ directory [\#173](https://github.com/arioch/puppet-redis/pull/173) ([petems](https://github.com/petems))
- Bump Beaker Ruby versions [\#172](https://github.com/arioch/puppet-redis/pull/172) ([petems](https://github.com/petems))
- Fixes sentinel installation on Debian flavours [\#171](https://github.com/arioch/puppet-redis/pull/171) ([petems](https://github.com/petems))
- Adds vagrant beaker images [\#170](https://github.com/arioch/puppet-redis/pull/170) ([petems](https://github.com/petems))
- Adds acceptance test for master/slave testing [\#168](https://github.com/arioch/puppet-redis/pull/168) ([petems](https://github.com/petems))
- Renames spec file [\#165](https://github.com/arioch/puppet-redis/pull/165) ([petems](https://github.com/petems))
- Adds specific versions to fixtures [\#164](https://github.com/arioch/puppet-redis/pull/164) ([petems](https://github.com/petems))
- Changes for RHEL-ish specific configuration [\#162](https://github.com/arioch/puppet-redis/pull/162) ([petems](https://github.com/petems))
- Changes CentOS Docker images [\#160](https://github.com/arioch/puppet-redis/pull/160) ([petems](https://github.com/petems))
- Updates fact for CentOS 6 [\#159](https://github.com/arioch/puppet-redis/pull/159) ([petems](https://github.com/petems))
- Fixes lint arrow errors [\#158](https://github.com/arioch/puppet-redis/pull/158) ([petems](https://github.com/petems))
- Fixes ownership issue on Ubuntu [\#157](https://github.com/arioch/puppet-redis/pull/157) ([petems](https://github.com/petems))
- README lint [\#155](https://github.com/arioch/puppet-redis/pull/155) ([matonb](https://github.com/matonb))
- Archlinux: Added tests and update config\_dir parameter [\#149](https://github.com/arioch/puppet-redis/pull/149) ([bartjanssens92](https://github.com/bartjanssens92))
- Add CHANGELOG [\#148](https://github.com/arioch/puppet-redis/pull/148) ([petems](https://github.com/petems))
- Added Archlinux as supported OS [\#147](https://github.com/arioch/puppet-redis/pull/147) ([bartjanssens92](https://github.com/bartjanssens92))

## [1.2.4](https://github.com/arioch/puppet-redis/tree/1.2.4) (2016-12-05)
[Full Changelog](https://github.com/arioch/puppet-redis/compare/1.2.3...1.2.4)

**Closed issues:**
**Implemented enhancements:**

- Wrong redis.conf after c45049986a7fcb1c9a0591de123c6bf97c761355 [\#142](https://github.com/arioch/puppet-redis/issues/142)
- Speed up Travis [\#118](https://github.com/arioch/puppet-redis/issues/118)
- Forge Release [\#110](https://github.com/arioch/puppet-redis/issues/110)
- git submodule issue? [\#104](https://github.com/arioch/puppet-redis/issues/104)

**Fixed bugs:**

- Wrong redis.conf after c45049986a7fcb1c9a0591de123c6bf97c761355 [\#142](https://github.com/arioch/puppet-redis/issues/142)
- powerstack.org - No longer hosted [\#103](https://github.com/arioch/puppet-redis/issues/103)
- Add support to custom repos with RedHat [\#91](https://github.com/arioch/puppet-redis/issues/91)

**Closed issues:**

- redis.conf under /etc/redis.conf [\#81](https://github.com/arioch/puppet-redis/issues/81)
- Add socket option [\#79](https://github.com/arioch/puppet-redis/issues/79)
- Can't run multiple instances [\#78](https://github.com/arioch/puppet-redis/issues/78)
- preinstall.pp fails on CEntOS 6.5 and Puppet Enterprise 2.7. [\#72](https://github.com/arioch/puppet-redis/issues/72)
- How do I change from powerstack.org repo if I need to? Should I just edit manifests/preinstall.pp? [\#68](https://github.com/arioch/puppet-redis/issues/68)
- puppet-redis || every time when puppet runs, the service restarts [\#59](https://github.com/arioch/puppet-redis/issues/59)
Expand All @@ -23,7 +103,7 @@

- For folks that do not use redis to cache to disk [\#144](https://github.com/arioch/puppet-redis/pull/144) ([petems](https://github.com/petems))
- Revert "Changes templates to use scope" [\#143](https://github.com/arioch/puppet-redis/pull/143) ([petems](https://github.com/petems))
- Update sentinel.pp [\#141](https://github.com/arioch/puppet-redis/pull/141) ([denis-sorokin](https://github.com/denis-sorokin))
- Update sentinel.pp [\#141](https://github.com/arioch/puppet-redis/pull/141) ([xprntl](https://github.com/xprntl))
- Manage workdir and permissions [\#138](https://github.com/arioch/puppet-redis/pull/138) ([petems](https://github.com/petems))
- Adds minimum versions parameters [\#137](https://github.com/arioch/puppet-redis/pull/137) ([petems](https://github.com/petems))
- Adds redis-server version fact [\#136](https://github.com/arioch/puppet-redis/pull/136) ([petems](https://github.com/petems))
Expand All @@ -49,10 +129,6 @@
## [1.2.3](https://github.com/arioch/puppet-redis/tree/1.2.3) (2016-09-19)
[Full Changelog](https://github.com/arioch/puppet-redis/compare/1.2.2...1.2.3)

**Closed issues:**

- Could not find declared class redis [\#96](https://github.com/arioch/puppet-redis/issues/96)

**Merged pull requests:**

- Adds spec for unixsocket and perms [\#99](https://github.com/arioch/puppet-redis/pull/99) ([petems](https://github.com/petems))
Expand All @@ -66,7 +142,6 @@

**Closed issues:**

- tcp-keepalive not supported in EPEL redis [\#87](https://github.com/arioch/puppet-redis/issues/87)
- Error 400 on SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type redis [\#86](https://github.com/arioch/puppet-redis/issues/86)
- Potential bug: `64min` should read `64mb` [\#73](https://github.com/arioch/puppet-redis/issues/73)
- Typo on sentinel.pp on if defined [\#69](https://github.com/arioch/puppet-redis/issues/69)
Expand Down Expand Up @@ -234,7 +309,7 @@

**Merged pull requests:**

- bugfix: Added puppetlabs/apt depedency and missing class include [\#5](https://github.com/arioch/puppet-redis/pull/5) ([n1tr0g](https://github.com/n1tr0g))
- bugfix: Added puppetlabs/apt depedency and missing class include [\#5](https://github.com/arioch/puppet-redis/pull/5) ([dgolja](https://github.com/dgolja))

## [0.0.6](https://github.com/arioch/puppet-redis/tree/0.0.6) (2013-08-07)
[Full Changelog](https://github.com/arioch/puppet-redis/compare/0.0.5...0.0.6)
Expand Down Expand Up @@ -266,4 +341,4 @@
## [0.0.1](https://github.com/arioch/puppet-redis/tree/0.0.1) (2013-06-19)


\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ group :test do
gem 'mock_redis', :require => false
end

group :development do
gem 'puppet-blacksmith'
end

group :system_tests do
gem "beaker", '2.41.0', :require => false
gem "beaker-rspec", '5.6.0', :require => false
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,24 @@ class { '::redis::sentinel':

## `redisget()` function

`redisget()` takes two arguments that are strings. The first is the key
to be looked up and the second is the URL to the Redis service.
`redisget()` takes two or three arguments that are strings. The first is the key
to be looked up, the second is the URL to the Redis service and the
optional third argument is a default value to use if the key is not
found or connection to the Redis service cannot be made.

Example of basic usage.

```puppet
$version = redisget('version.myapp', 'redis://redis.example.com:6379')
```

Example with default value specified. This is useful to allow for cached
data in case Redis is not available.

```puppet
$version = redisget('version.myapp', 'redis://redis.example.com:6379', $::myapp_version)
```

You must have the 'redis' gem installed on your puppet master.

## Unit testing
Expand Down
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
require 'puppet-syntax/tasks/puppet-syntax'

# These two gems aren't always present, for instance
# on Travis with --without development
begin
require 'puppet_blacksmith/rake_tasks'
rescue LoadError
end

PuppetLint.configuration.fail_on_warnings
PuppetLint.configuration.send('relative')
PuppetLint.configuration.send('disable_80chars')
Expand Down
34 changes: 19 additions & 15 deletions lib/puppet/parser/functions/getvar_emptystring.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
module Puppet::Parser::Functions

newfunction(:getvar_emptystring, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
Lookup a variable in a remote namespace.
Return an empty string rather than undef/nil if it could not be found
For example:
$foo = getvar('site::data::foo')
# Equivalent to $foo = $site::data::foo
This is useful if the namespace itself is stored in a string:
$datalocation = 'site::data'
$bar = getvar("${datalocation}::bar")
# Equivalent to $bar = $site::data::bar
ENDHEREDOC
newfunction(:getvar_emptystring, :type => :rvalue, :doc => <<-DOC
Return a variable in a remote namespace, but returns an empty
string if the variable is undefined or can't be found.
This is useful when trying to lookup a value that might be undefined
on first run, like a fact for an application that will be installed as
part of a Puppet run, but you don't want the reference to an undefined variable
to cause an error when strict variables are enabled.
@param variable [String] The variable to lookup
@return [String] The value of the variable if found
@return [String] An empty string if the variable is not found eg. `''`
@example Checking a variable exists (Equivalent to $foo = $site::data::foo)
$foo = getvar('site::data::foo')
@example Calling the function. (Equivalent to $bar = $site::data::bar)
$datalocation = 'site::data'
$bar = getvar("${datalocation}::bar")
@example Combining with the pick() function
$redis_version_real = pick(getvar_emptystring('redis_server_version'), '3.2.1')
DOC
) do |args|

unless args.length == 1
raise Puppet::ParseError, ("getvar_emptystring(): wrong number of arguments (#{args.length}; must be 1)")
Expand Down
51 changes: 41 additions & 10 deletions lib/puppet/parser/functions/redisget.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
require 'redis'

module Puppet::Parser::Functions
newfunction(:redisget, :type => :rvalue, :doc => <<-EOS
Returns the value of the key being looked up or nil if the key does not
exist. Takes two arguments, the first being a string value of the key to be
looked up and the second is the URL to the Redis service.
EOS
newfunction(:redisget, :type => :rvalue, :doc => <<-DOC
Returns the value of the key being looked up or nil if the key does not
exist. Takes two arguments with an optional third. The first being a string
value of the key to be looked up, the second is the URL to the Redis service
and the third optional argument is a default value to be used if the lookup
fails.
@param redis_key [String] The key to look up in redis.
@param redis_uri [String] The endpoint of the Redis instance.
@param default_value [String] The value to return if the key is not found or
the connection to Redis fails
@return [String] The value of the key from redis
@return [String] An empty string eg. `''`
@example Calling the function.
$version = redisget('version.myapp', 'redis://redis.example.com:6379')
@example Calling the function with a default if failure occurs
$version = redisget('version.myapp', 'redis://redis.example.com:6379', $::myapp_version)
DOC
) do |args|

raise(Puppet::ParseError, "redisget(): Wrong number of arguments given (#{args.size} for 2)") if args.size != 2
raise(Puppet::ParseError, "redisget(): Wrong number of arguments given (#{args.size} for 2 or 3)") if args.size != 2 and args.size != 3

key = args[0]
url = args[1]

raise(Puppet::ParseError, "redisget(): Wrong argument type given (#{key.class} for String") if key.is_a?(String) == false
raise(Puppet::ParseError, "redisget(): Wrong argument type given (#{url.class} for String") if url.is_a?(String) == false
if args.size == 3
default = args[2]
raise(Puppet::ParseError, "redisget(): Wrong argument type given (#{default.class} for String) for arg3 (default)") if default.is_a?(String) == false
end

redis = Redis.new(:url => url)
redis.get(key)
raise(Puppet::ParseError, "redisget(): Wrong argument type given (#{key.class} for String) for arg1 (key)") if key.is_a?(String) == false
raise(Puppet::ParseError, "redisget(): Wrong argument type given (#{url.class} for String) for arg2 (url)") if url.is_a?(String) == false

begin
redis = Redis.new(:url => url)
returned_value = redis.get(key)
if returned_value == nil and defined?(default) != nil
default
else
returned_value
end
rescue Exception => e
if default
debug "Connection to redis failed with #{e} - Returning default value of #{default}"
default
else
raise(Puppet::Error, "connection to redis server failed - #{e}")
end
end
end
end
28 changes: 16 additions & 12 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,24 @@
owner => $::redis::config_owner,
}

case $::operatingsystem {
'Debian': {
$var_run_redis_mode = '2775'
}
default: {
$var_run_redis_mode = '0755'
$service_provider_lookup = pick(getvar_emptystring('service_provider'), false)

if $service_provider_lookup != 'systemd' {
case $::operatingsystem {
'Debian': {
$var_run_redis_mode = '2775'
}
default: {
$var_run_redis_mode = '0755'
}
}
}

file { '/var/run/redis':
ensure => 'directory',
owner => $::redis::config_owner,
group => $::redis::config_group,
mode => $var_run_redis_mode,
file { '/var/run/redis':
ensure => 'directory',
owner => $::redis::config_owner,
group => $::redis::config_group,
mode => $var_run_redis_mode,
}
}

}
Expand Down
7 changes: 4 additions & 3 deletions manifests/ulimit.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
}
if $service_provider_lookup == 'systemd' {
file { "/etc/systemd/system/${::redis::service_name}.service.d/":
ensure => 'directory',
owner => 'root',
group => 'root',
ensure => 'directory',
owner => 'root',
group => 'root',
selinux_ignore_defaults => true,
}

file { "/etc/systemd/system/${::redis::service_name}.service.d/limit.conf":
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arioch-redis",
"version": "3.0.0",
"version": "3.1.0",
"author": "Tom De Vylder",
"summary": "Redis module",
"license": "Apache-2.0",
Expand Down
Loading