2 changes: 2 additions & 0 deletions .fixtures-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ fixtures:
repo: git://github.com/puppetlabs/puppetlabs-postgresql.git
archive:
repo: git://github.com/voxpupuli/puppet-archive.git
windows_env:
repo: git://github.com/voxpupuli/puppet-windows_env.git
symlinks:
sensu: "#{source_dir}"
3 changes: 3 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ fixtures:
archive:
repo: git://github.com/voxpupuli/puppet-archive.git
ref: 'v3.0.0'
windows_env:
repo: git://github.com/voxpupuli/puppet-windows_env.git
ref: 'v3.0.0'
symlinks:
sensu: "#{source_dir}"
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [v3.14.0](https://github.com/sensu/sensu-puppet/tree/v3.14.0) (2019-12-01)

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v3.13.0...v3.14.0)

### Added

- Support defining agent and backend service environment variables [\#1160](https://github.com/sensu/sensu-puppet/pull/1160) ([treydock](https://github.com/treydock))

## [v3.13.0](https://github.com/sensu/sensu-puppet/tree/v3.13.0) (2019-11-26)

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v3.12.0...v3.13.0)
Expand Down Expand Up @@ -52,8 +60,6 @@
### Added

- Initial work at design document [\#1161](https://github.com/sensu/sensu-puppet/pull/1161) ([treydock](https://github.com/treydock))
- Add bolt tasks [\#1153](https://github.com/sensu/sensu-puppet/pull/1153) ([treydock](https://github.com/treydock))
- Deprecate defining single asset builds [\#1140](https://github.com/sensu/sensu-puppet/pull/1140) ([treydock](https://github.com/treydock))

## [v3.9.0](https://github.com/sensu/sensu-puppet/tree/v3.9.0) (2019-10-10)

Expand All @@ -63,9 +69,11 @@

- Add sensu\_resources type that will handle resource purging [\#1158](https://github.com/sensu/sensu-puppet/pull/1158) ([treydock](https://github.com/treydock))
- Add sensu\_gem package provider [\#1156](https://github.com/sensu/sensu-puppet/pull/1156) ([treydock](https://github.com/treydock))
- Add bolt tasks [\#1153](https://github.com/sensu/sensu-puppet/pull/1153) ([treydock](https://github.com/treydock))
- Install Windows agent via chocolatey [\#1152](https://github.com/sensu/sensu-puppet/pull/1152) ([treydock](https://github.com/treydock))
- Add sensu\_bonsai\_asset type [\#1149](https://github.com/sensu/sensu-puppet/pull/1149) ([treydock](https://github.com/treydock))
- Replace unit test instance variables with let [\#1143](https://github.com/sensu/sensu-puppet/pull/1143) ([treydock](https://github.com/treydock))
- Deprecate defining single asset builds [\#1140](https://github.com/sensu/sensu-puppet/pull/1140) ([treydock](https://github.com/treydock))

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ If managing Windows there is a soft dependency on the [puppetlabs/chocolatey](ht

If managing Windows and defining `package_source`, there is a soft dependency on the [puppet/archive](https://forge.puppet.com/puppet/archive) module (`>= 3.0.0 < 5.0.0`).

If managing Windows and defining `service_env_vars` there is a soft depedency on [puppet/windows_env](https://forge.puppet.com/puppet/windows_env) module (`>= 3.0.0 < 4.0.0`)

For PostgreSQL datastore support there is a soft dependency on [puppetlabs/postgresql](https://forge.puppet.com/puppetlabs/postgresql) module (`>= 6.0.0 < 7.0.0`).

### Beginning with sensu
Expand Down
36 changes: 36 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,24 @@ Name of Sensu agent package.

Default value: 'sensu-go-agent'

##### `service_env_vars_file`

Data type: `Optional[Stdlib::Absolutepath]`

Path to the agent service ENV variables file.
Debian based default: `/etc/default/sensu-agent`
RedHat based default: `/etc/sysconfig/sensu-agent`

Default value: `undef`

##### `service_env_vars`

Data type: `Hash`

Hash of environment variables loaded by sensu-agent service

Default value: {}

##### `service_name`

Data type: `String`
Expand Down Expand Up @@ -323,6 +341,24 @@ Name of Sensu CLI package.

Default value: 'sensu-go-cli'

##### `service_env_vars_file`

Data type: `Optional[Stdlib::Absolutepath]`

Path to the backend service ENV variables file.
Debian based default: `/etc/default/sensu-backend`
RedHat based default: `/etc/sysconfig/sensu-backend`

Default value: `undef`

##### `service_env_vars`

Data type: `Hash`

Hash of environment variables loaded by sensu-backend service

Default value: {}

##### `service_name`

Data type: `String`
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ install:
- puppet module install puppetlabs-stdlib
- puppet module install puppetlabs-chocolatey
- puppet module install puppet-archive
- puppet module install puppet-windows_env
- puppet config set --section main certname sensu_agent
- facter -p --debug
- ruby -v
Expand Down
2 changes: 2 additions & 0 deletions data/os/Debian.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
sensu::agent::service_env_vars_file: /etc/default/sensu-agent
sensu::backend::service_env_vars_file: /etc/default/sensu-backend
sensu::plugins::dependencies:
- make
- gcc
Expand Down
2 changes: 2 additions & 0 deletions data/os/RedHat.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
sensu::agent::service_env_vars_file: /etc/sysconfig/sensu-agent
sensu::backend::service_env_vars_file: /etc/sysconfig/sensu-backend
sensu::plugins::dependencies:
- make
- gcc
Expand Down
38 changes: 38 additions & 0 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
# This parameter only used when `package_source` is an URL or when it's a puppet source (`puppet://`).
# @param package_name
# Name of Sensu agent package.
# @param service_env_vars_file
# Path to the agent service ENV variables file.
# Debian based default: `/etc/default/sensu-agent`
# RedHat based default: `/etc/sysconfig/sensu-agent`
# @param service_env_vars
# Hash of environment variables loaded by sensu-agent service
# @param service_name
# Name of the Sensu agent service.
# @param service_ensure
Expand All @@ -46,6 +52,8 @@
Optional[String[1]] $package_source = undef,
Optional[Stdlib::Absolutepath] $package_download_path = undef,
String $package_name = 'sensu-go-agent',
Optional[Stdlib::Absolutepath] $service_env_vars_file = undef,
Hash $service_env_vars = {},
String $service_name = 'sensu-agent',
String $service_ensure = 'running',
Boolean $service_enable = true,
Expand Down Expand Up @@ -84,6 +92,10 @@
'backend-url' => $backend_urls,
}
$config = $default_config + $ssl_config + $config_hash
$_service_env_vars = $service_env_vars.map |$key,$value| {
"${key}=\"${value}\""
}
$_service_env_vars_lines = ['# This file is being maintained by Puppet.','# DO NOT EDIT'] + $_service_env_vars

if $facts['os']['family'] == 'windows' {
$sensu_agent_exe = "C:\\Program Files\\sensu\\sensu-agent\\bin\\sensu-agent.exe"
Expand Down Expand Up @@ -151,6 +163,32 @@
notify => Service['sensu-agent'],
}

if $service_env_vars_file {
$_service_env_vars_content = join($_service_env_vars_lines, "\n")
file { 'sensu-agent_env_vars':
ensure => 'file',
path => $service_env_vars_file,
content => "${_service_env_vars_content}\n",
owner => $::sensu::sensu_user,
group => $::sensu::sensu_group,
mode => $::sensu::file_mode,
show_diff => $show_diff,
require => Package['sensu-go-agent'],
notify => Service['sensu-agent'],
}
}
# No built in way to read environment variables from a file for Windows
if $facts['os']['family'] == 'windows' {
$service_env_vars.each |$key,$value| {
windows_env { $key:
ensure => 'present',
value => $value,
mergemode => 'clobber',
notify => Service['sensu-agent'],
}
}
}

service { 'sensu-agent':
ensure => $service_ensure,
enable => $service_enable,
Expand Down
28 changes: 27 additions & 1 deletion manifests/backend.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
# Name of Sensu backend package.
# @param cli_package_name
# Name of Sensu CLI package.
# @param service_env_vars_file
# Path to the backend service ENV variables file.
# Debian based default: `/etc/default/sensu-backend`
# RedHat based default: `/etc/sysconfig/sensu-backend`
# @param service_env_vars
# Hash of environment variables loaded by sensu-backend service
# @param service_name
# Name of the Sensu backend service.
# @param service_ensure
Expand Down Expand Up @@ -127,6 +133,8 @@
Optional[String] $version = undef,
String $package_name = 'sensu-go-backend',
String $cli_package_name = 'sensu-go-cli',
Optional[Stdlib::Absolutepath] $service_env_vars_file = undef,
Hash $service_env_vars = {},
String $service_name = 'sensu-backend',
String $service_ensure = 'running',
Boolean $service_enable = true,
Expand Down Expand Up @@ -229,7 +237,10 @@
'api-url' => $url,
}
$config = $default_config + $ssl_config + $config_hash

$_service_env_vars = $service_env_vars.map |$key,$value| {
"${key}=\"${value}\""
}
$_service_env_vars_lines = ['# This file is being maintained by Puppet.','# DO NOT EDIT'] + $_service_env_vars

if $include_default_resources {
include ::sensu::backend::default_resources
Expand Down Expand Up @@ -342,6 +353,21 @@
notify => Service['sensu-backend'],
}

if $service_env_vars_file {
$_service_env_vars_content = join($_service_env_vars_lines, "\n")
file { 'sensu-backend_env_vars':
ensure => 'file',
path => $service_env_vars_file,
content => "${_service_env_vars_content}\n",
owner => $::sensu::sensu_user,
group => $::sensu::sensu_group,
mode => '0640',
show_diff => $show_diff,
require => Package['sensu-go-backend'],
notify => Service['sensu-backend'],
}
}

service { 'sensu-backend':
ensure => $service_ensure,
enable => $service_enable,
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": "sensu-sensu",
"version": "3.13.0",
"version": "3.14.0",
"author": "sensu",
"summary": "A module to install the Sensu monitoring framework",
"license": "MIT",
Expand Down
33 changes: 33 additions & 0 deletions spec/acceptance/00_backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,39 @@ class { '::sensu::backend':
end
end

context 'service env_vars' do
it 'should work without errors' do
pp = <<-EOS
class { '::sensu': }
class { '::sensu::backend':
password => 'supersecret',
old_password => 'P@ssw0rd!',
service_env_vars => { 'SENSU_BACKEND_AGENT_PORT' => '9081' },
}
EOS

if RSpec.configuration.sensu_use_agent
site_pp = "node 'sensu_backend' { #{pp} }"
puppetserver = hosts_as('puppetserver')[0]
create_remote_file(puppetserver, "/etc/puppetlabs/code/environments/production/manifests/site.pp", site_pp)
on node, puppet("agent -t --detailed-exitcodes"), acceptable_exit_codes: [0,2]
on node, puppet("agent -t --detailed-exitcodes"), acceptable_exit_codes: [0]
else
# Run it twice and test for idempotency
apply_manifest_on(node, pp, :catch_failures => true)
apply_manifest_on(node, pp, :catch_changes => true)
end
end

describe service('sensu-backend'), :node => node do
it { should be_enabled }
it { should be_running }
end
describe port(9081), :node => node do
it { should be_listening }
end
end

context 'backend and agent' do
it 'should work without errors' do
pp = <<-EOS
Expand Down
7 changes: 6 additions & 1 deletion spec/acceptance/01_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class { '::sensu::agent':
backends => ['sensu_backend:8081'],
config_hash => {
'name' => 'sensu_agent',
}
},
service_env_vars => { 'SENSU_API_PORT' => '4041' },
}
EOS

Expand All @@ -31,5 +32,9 @@ class { '::sensu::agent':
it { should be_enabled }
it { should be_running }
end

describe port(4041), :node => node do
it { should be_listening }
end
end
end
4 changes: 2 additions & 2 deletions spec/acceptance/nodesets/centos-7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ HOSTS:
- '/usr/sbin/init'
docker_image_commands:
- "sed -i -r '/^tsflags/d' /etc/yum.conf"
- 'yum install -y wget which'
- 'yum install -y wget which iproute'
docker_container_name: 'sensu-agent-el7'
sensu_backend:
roles:
Expand All @@ -27,7 +27,7 @@ HOSTS:
- '/usr/sbin/init'
docker_image_commands:
- "sed -i -r '/^tsflags/d' /etc/yum.conf"
- 'yum install -y wget which initscripts'
- 'yum install -y wget which initscripts iproute'
docker_container_name: 'sensu-backend-el7'
CONFIG:
log_level: debug
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/nodesets/ubuntu-1804.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ HOSTS:
docker_image_commands:
- "rm -f /etc/dpkg/dpkg.cfg.d/excludes"
- 'apt-get update'
- 'apt-get install -y -q net-tools wget curl locales'
- 'apt-get install -y -q net-tools wget curl locales iproute2'
- 'locale-gen en_US.UTF-8'
docker_container_name: 'sensu-agent-ubuntu1804'
sensu_backend:
Expand All @@ -26,7 +26,7 @@ HOSTS:
docker_cmd: '["/sbin/init"]'
docker_image_commands:
- "rm -f /etc/dpkg/dpkg.cfg.d/excludes"
- 'apt-get install -y -q net-tools wget locales'
- 'apt-get install -y -q net-tools wget locales iproute2'
- 'locale-gen en_US.UTF-8'
docker_container_name: 'sensu-backend-ubuntu1804'
CONFIG:
Expand Down
6 changes: 5 additions & 1 deletion spec/acceptance/windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class { '::sensu::agent':
backends => ['sensu_backend:8081'],
config_hash => {
'name' => 'sensu_agent',
}
},
service_env_vars => { 'SENSU_API_PORT' => '4041' },
}
EOS

Expand Down Expand Up @@ -71,6 +72,9 @@ class { '::sensu::agent':
it { should be_enabled }
it { should be_running }
end
describe port(4041) do
it { should be_listening }
end
describe 'sensu_agent.version fact' do
it 'has version fact' do
output = `facter --json -p sensu_agent`
Expand Down
Loading