Skip to content

Commit

Permalink
Merge pull request #540 from Joris29/Update_project_management
Browse files Browse the repository at this point in the history
Add multiple small code additions and improvements
  • Loading branch information
bastelfreak committed May 14, 2024
2 parents 8e20762 + 7deaf8f commit df94bd6
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 36 deletions.
23 changes: 21 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

* [`rundeck::config::aclpolicyfile`](#rundeck--config--aclpolicyfile): This define will create a custom acl policy file.
* [`rundeck::config::plugin`](#rundeck--config--plugin): This define will install a rundeck plugin.
* [`rundeck::config::project`](#rundeck--config--project): This define will create and manage a rundeck project.
* [`rundeck::config::project`](#rundeck--config--project): This define will manage projects and jobs.

### Functions

Expand Down Expand Up @@ -74,6 +74,7 @@ The following parameters are available in the `rundeck` class:
* [`quartz_job_threadcount`](#-rundeck--quartz_job_threadcount)
* [`auth_config`](#-rundeck--auth_config)
* [`database_config`](#-rundeck--database_config)
* [`feature_config`](#-rundeck--feature_config)
* [`framework_config`](#-rundeck--framework_config)
* [`gui_config`](#-rundeck--gui_config)
* [`mail_config`](#-rundeck--mail_config)
Expand Down Expand Up @@ -377,6 +378,14 @@ Hash of properties for configuring the [Rundeck Database](https://docs.rundeck.c

Default value: `{ 'url' => 'jdbc:h2:file:/var/lib/rundeck/data/rundeckdb' }`

##### <a name="-rundeck--feature_config"></a>`feature_config`

Data type: `Hash`

A hash of rundeck features.

Default value: `{}`

##### <a name="-rundeck--framework_config"></a>`framework_config`

Data type: `Hash`
Expand Down Expand Up @@ -983,7 +992,7 @@ Default value: `undef`

### <a name="rundeck--config--project"></a>`rundeck::config::project`

This define will create and manage a rundeck project.
This define will manage projects and jobs.

#### Examples

Expand All @@ -1002,10 +1011,19 @@ rundeck::config::project { 'MyProject':

The following parameters are available in the `rundeck::config::project` defined type:

* [`ensure`](#-rundeck--config--project--ensure)
* [`config`](#-rundeck--config--project--config)
* [`update_method`](#-rundeck--config--project--update_method)
* [`jobs`](#-rundeck--config--project--jobs)

##### <a name="-rundeck--config--project--ensure"></a>`ensure`

Data type: `Enum['absent', 'present']`

Whether or not the project should be present.

Default value: `'present'`

##### <a name="-rundeck--config--project--config"></a>`config`

Data type: `Hash[String, String]`
Expand Down Expand Up @@ -1155,6 +1173,7 @@ Alias of

```puppet
Struct[{
Optional['ensure'] => Enum['absent', 'present'],
Optional['config'] => Hash[String, String],
Optional['update_method'] => Enum['set', 'update'],
Optional['jobs'] => Hash[String, Rundeck::Job],
Expand Down
64 changes: 38 additions & 26 deletions manifests/config/project.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @summary This define will create and manage a rundeck project.
# @summary This define will manage projects and jobs.
#
# @example Basic usage.
# rundeck::config::project { 'MyProject':
Expand All @@ -8,6 +8,8 @@
# },
# }
#
# @param ensure
# Whether or not the project should be present.
# @param config
# Configuration properties for a project.
# @param update_method
Expand All @@ -17,6 +19,7 @@
# Rundeck jobs related to a project.
#
define rundeck::config::project (
Enum['absent', 'present'] $ensure = 'present',
Hash[String, String] $config = {
'project.description' => "${name} project",
'project.label' => $name,
Expand Down Expand Up @@ -49,35 +52,44 @@
default => "rd_project_diff.sh '${name}' ${update_method} '${_final_cfg.to_json}' '${_final_cfg.keys}'",
}

exec {
default:
if $ensure == 'absent' {
exec { "Remove rundeck project: ${name}":
command => "rd projects delete -y -p '${name}'",
path => ['/bin', '/usr/bin', '/usr/local/bin'],
environment => $rundeck::cli::environment,
;
"Create rundeck project: ${name}":
command => "rd projects create -p ${name}",
unless => "rd projects info -p ${name}",
;
"Manage rundeck project: ${name}":
command => "rd projects configure ${update_method} -p ${name} -- ${_cmd_line_cfg.shellquote}",
unless => $_project_diff,
;
}

$jobs.each |$_name, $_attr| {
if $_attr['ensure'] == 'absent' {
exec { "(${name}) Remove job: ${_name}":
command => "rd jobs purge -y -p '${name}' -J '${_name}'",
path => ['/bin', '/usr/bin', '/usr/local/bin'],
environment => $rundeck::cli::environment,
onlyif => "rd jobs list -p '${name}' -J '${_name}' | grep -q '${_name}'",
}
} else {
exec { "(${name}) Create/update job: ${_name}":
command => "rd jobs load -d update -p '${name}' -f '${_attr['path']}' -F ${_attr['format']}",
onlyif => "rd projects info -p '${name}'",
}
} else {
exec {
default:
path => ['/bin', '/usr/bin', '/usr/local/bin'],
environment => $rundeck::cli::environment,
unless => "rd_job_diff.sh '${name}' '${_name}' '${_attr['path']}' ${_attr['format']}",
;
"Create rundeck project: ${name}":
command => "rd projects create -p '${name}' -- ${_cmd_line_cfg.shellquote}",
unless => "rd projects info -p '${name}'",
;
"Manage rundeck project: ${name}":
command => "rd projects configure ${update_method} -p '${name}' -- ${_cmd_line_cfg.shellquote}",
unless => $_project_diff,
;
}

$jobs.each |$_name, $_attr| {
if $_attr['ensure'] == 'absent' {
exec { "(${name}) Remove job: ${_name}":
command => "rd jobs purge -y -p '${name}' -J '${_name}'",
path => ['/bin', '/usr/bin', '/usr/local/bin'],
environment => $rundeck::cli::environment,
onlyif => "rd jobs list -p '${name}' -J '${_name}' | grep -q '${_name}'",
}
} else {
exec { "(${name}) Create/update job: ${_name}":
command => "rd jobs load -d update -p '${name}' -f '${_attr['path']}' -F ${_attr['format']}",
path => ['/bin', '/usr/bin', '/usr/local/bin'],
environment => $rundeck::cli::environment,
unless => "rd_job_diff.sh '${name}' '${_name}' '${_attr['path']}' ${_attr['format']}",
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
# Hash of properties for configuring [Rundeck JAAS Authentication](https://docs.rundeck.com/docs/administration/security/authentication.html#jetty-and-jaas-authentication)
# @param database_config
# Hash of properties for configuring the [Rundeck Database](https://docs.rundeck.com/docs/administration/configuration/database)
# @param feature_config
# A hash of rundeck features.
# @param framework_config
# Hash of properties for configuring the [Rundeck Framework](https://docs.rundeck.com/docs/administration/configuration/config-file-reference.html#framework-properties)
# This hash will be merged with the [Rundeck defaults](https://github.com/voxpupuli/puppet-rundeck/blob/master/manifests/config.pp#L8-L20)
Expand Down Expand Up @@ -217,6 +219,7 @@
},
},
Rundeck::Db_config $database_config = { 'url' => 'jdbc:h2:file:/var/lib/rundeck/data/rundeckdb' },
Hash $feature_config = {},
Hash $framework_config = {},
Hash $gui_config = {},
Rundeck::Mail_config $mail_config = {},
Expand Down
3 changes: 3 additions & 0 deletions spec/acceptance/hieradata/family/RedHat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Rundeck 5.0.0 or newer requires Java 11 minimum
java::package: java-11-openjdk-headless
6 changes: 3 additions & 3 deletions spec/acceptance/rundeck_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
it 'applies successfully' do
pp = <<-EOS
class { 'java':
distribution => 'jre'
distribution => 'jre',
}
class { 'rundeck':
package_ensure => '4.17.2.20231107-1'
package_ensure => '5.0.2.20240212-1',
}
Class['java'] -> Class['rundeck']
Expand All @@ -35,7 +35,7 @@ class { 'rundeck':
it 'applies successfully' do
pp = <<-EOS
class { 'rundeck':
package_ensure => '4.17.4.20231216-1'
package_ensure => '5.2.0.20240410-1',
}
EOS

Expand Down
17 changes: 17 additions & 0 deletions spec/defines/config/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

it do
is_expected.to contain_rundeck__config__project('MyProject').with(
ensure: 'present',
update_method: 'update',
config: {
'project.description' => 'MyProject project',
Expand Down Expand Up @@ -52,6 +53,7 @@

it do
is_expected.to contain_rundeck__config__project('TestProject').with(
ensure: 'present',
update_method: 'set',
config: {
'project.description' => 'This is a rundeck test project',
Expand All @@ -64,6 +66,20 @@
it { is_expected.to contain_exec('Manage rundeck project: TestProject') }
end

context 'Remove rundeck project: RemoveProject' do
name = 'RemoveProject'

let(:title) { name }
let(:params) do
{
ensure: 'absent',
}
end

it { is_expected.to contain_rundeck__config__project('RemoveProject').with(ensure: 'absent') }
it { is_expected.to contain_exec('Remove rundeck project: RemoveProject') }
end

context 'Add rundeck project: MyJobProject with jobs' do
name = 'MyJobProject'

Expand Down Expand Up @@ -98,6 +114,7 @@

it do
is_expected.to contain_rundeck__config__project('MyJobProject').with(
ensure: 'present',
update_method: 'update',
config: {
'project.description' => 'This is a rundeck project with jobs',
Expand Down
4 changes: 4 additions & 0 deletions templates/rundeck-config.properties.epp
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ rundeck.security.authorization.preauthenticated.<%= $_k %> = <%= $_v %>
<%- $rundeck::gui_config.each |$_k, $_v| {-%>
rundeck.gui.<%= $_k %> = <%= $_v %>
<%- } -%>

<%- $rundeck::feature_config.each |$_k, $_v| {-%>
rundeck.feature.<%= $_k %> = <%= $_v %>
<%- } -%>
2 changes: 1 addition & 1 deletion types/auth_config.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Rundeck authentication config type.
# @summary Rundeck authentication config type.
type Rundeck::Auth_config = Struct[{
Optional['file'] => Hash[String, Any],
Optional['ldap'] => Hash[String, Any],
Expand Down
2 changes: 1 addition & 1 deletion types/db_config.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Rundeck database config type.
# @summary Rundeck database config type.
type Rundeck::Db_config = Struct[{
'url' => String,
Optional['driverClassName'] => String,
Expand Down
2 changes: 1 addition & 1 deletion types/key_storage_config.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Rundeck key storage config type.
# @summary Rundeck key storage config type.
type Rundeck::Key_storage_config = Array[
Struct[{
'type' => String,
Expand Down
2 changes: 1 addition & 1 deletion types/loglevel.pp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Rundeck log level type.
# @summary Rundeck log level type.
type Rundeck::Loglevel = Enum['all', 'debug', 'error', 'fatal', 'info', 'off', 'trace', 'warn']
2 changes: 1 addition & 1 deletion types/mail_config.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Rundeck mail config type.
# @summary Rundeck mail config type.
type Rundeck::Mail_config = Struct[{
Optional['host'] => String,
Optional['port'] => Integer,
Expand Down
1 change: 1 addition & 0 deletions types/project.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @summary Rundeck project type.
type Rundeck::Project = Struct[{
Optional['ensure'] => Enum['absent', 'present'],
Optional['config'] => Hash[String, String],
Optional['update_method'] => Enum['set', 'update'],
Optional['jobs'] => Hash[String, Rundeck::Job],
Expand Down

0 comments on commit df94bd6

Please sign in to comment.