Skip to content

Commit

Permalink
Merge pull request #530 from Joris29/job_management
Browse files Browse the repository at this point in the history
Add Job management
  • Loading branch information
bastelfreak committed Feb 29, 2024
2 parents ecc8c30 + b72ed4a commit 59880bb
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 52 deletions.
59 changes: 46 additions & 13 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@

* [`Rundeck::Auth_config`](#Rundeck--Auth_config): Rundeck authentication config type.
* [`Rundeck::Db_config`](#Rundeck--Db_config): Rundeck database config type.
* [`Rundeck::Job`](#Rundeck--Job): Rundeck job type.
* [`Rundeck::Key_storage_config`](#Rundeck--Key_storage_config): Rundeck key storage config type.
* [`Rundeck::Loglevel`](#Rundeck--Loglevel): Rundeck log level type.
* [`Rundeck::Mail_config`](#Rundeck--Mail_config): Rundeck mail config type.
* [`Rundeck::Project`](#Rundeck--Project): Rundeck project config type.
* [`Rundeck::Project`](#Rundeck--Project): Rundeck project type.

## Classes

Expand Down Expand Up @@ -699,6 +700,7 @@ The following parameters are available in the `rundeck::cli` class:

* [`repo_config`](#-rundeck--cli--repo_config)
* [`manage_repo`](#-rundeck--cli--manage_repo)
* [`notify_conn_check`](#-rundeck--cli--notify_conn_check)
* [`version`](#-rundeck--cli--version)
* [`url`](#-rundeck--cli--url)
* [`bypass_url`](#-rundeck--cli--bypass_url)
Expand All @@ -722,6 +724,14 @@ Whether to manage the cli package repository.

Default value: `true`

##### <a name="-rundeck--cli--notify_conn_check"></a>`notify_conn_check`

Data type: `Boolean`

Wheter to notify the cli connection check if rundeck service changes.

Default value: `false`

##### <a name="-rundeck--cli--version"></a>`version`

Data type: `String[1]`
Expand Down Expand Up @@ -956,17 +966,9 @@ rundeck::config::project { 'MyProject':

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

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

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

Data type: `Enum['set', 'update']`

set: Overwrite all configuration properties for a project. Any config keys not included will be removed.
update: Modify configuration properties for a project. Only the specified keys will be updated.

Default value: `'update'`
* [`update_method`](#-rundeck--config--project--update_method)
* [`jobs`](#-rundeck--config--project--jobs)

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

Expand All @@ -991,6 +993,23 @@ Default value:
}
```

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

Data type: `Enum['set', 'update']`

set: Overwrite all configuration properties for a project. Any config keys not included will be removed.
update: Modify configuration properties for a project. Only the specified keys will be updated.

Default value: `'update'`

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

Data type: `Hash[String, Rundeck::Job]`

Rundeck jobs related to a project.

Default value: `{}`

## Functions

### <a name="validate_rd_policy"></a>`validate_rd_policy`
Expand Down Expand Up @@ -1038,6 +1057,19 @@ Struct[{
}]
```

### <a name="Rundeck--Job"></a>`Rundeck::Job`

Rundeck job type.

Alias of

```puppet
Struct[{
'path' => Stdlib::Absolutepath,
'format' => Enum['yaml', 'xml', 'json'],
}]
```

### <a name="Rundeck--Key_storage_config"></a>`Rundeck::Key_storage_config`

Rundeck key storage config type.
Expand Down Expand Up @@ -1080,14 +1112,15 @@ Struct[{

### <a name="Rundeck--Project"></a>`Rundeck::Project`

Rundeck project config type.
Rundeck project type.

Alias of

```puppet
Struct[{
Optional['config'] => Hash[String, String],
Optional['update_method'] => String,
Optional['update_method'] => Enum['set', 'update'],
Optional['jobs'] => Hash[String, Rundeck::Job],
}]
```

18 changes: 18 additions & 0 deletions files/rd_job_diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
# THIS FILE IS MANAGED BY PUPPET

project="$1"
job="$2"
path="$3"
format="$4"

temp_file=$(mktemp "/tmp/$job.$format.XXXX")

rd jobs list -p "$project" -J "$job" -f "$temp_file" -F $format

cmp -s "$path" "$temp_file"
cmp_status=$?

rm "$temp_file"

exit $cmp_status
22 changes: 18 additions & 4 deletions manifests/cli.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
# Examples/defaults for yumrepo can be found at RedHat.yaml, and for apt at Debian.yaml
# @param manage_repo
# Whether to manage the cli package repository.
# @param notify_conn_check
# Wheter to notify the cli connection check if rundeck service changes.
# @param version
# Ensure the state of the rundeck cli package, either present, absent or a specific version.
# @param url
Expand All @@ -46,6 +48,7 @@
class rundeck::cli (
Hash $repo_config,
Boolean $manage_repo = true,
Boolean $notify_conn_check = false,
String[1] $version = 'installed',
Stdlib::HTTPUrl $url = 'http://localhost:4440',
Stdlib::HTTPUrl $bypass_url = 'http://localhost:4440',
Expand All @@ -56,6 +59,10 @@
) {
ensure_resource('package', 'jq', { 'ensure' => 'present' })

if $notify_conn_check {
Class['rundeck::service'] ~> Exec['Check rundeck cli connection']
}

case $facts['os']['family'] {
'RedHat': {
if $manage_repo {
Expand Down Expand Up @@ -88,10 +95,17 @@
ensure => $version,
}

file { '/usr/local/bin/rd_project_diff.sh':
ensure => file,
content => file('rundeck/rd_project_diff.sh'),
mode => '0755',
file {
default:
ensure => file,
mode => '0755',
;
'/usr/local/bin/rd_project_diff.sh':
content => file('rundeck/rd_project_diff.sh'),
;
'/usr/local/bin/rd_job_diff.sh':
content => file('rundeck/rd_job_diff.sh'),
;
}

$_default_env_vars = [
Expand Down
27 changes: 24 additions & 3 deletions manifests/config/project.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
# },
# }
#
# @param config
# Configuration properties for a project.
# @param update_method
# set: Overwrite all configuration properties for a project. Any config keys not included will be removed.
# update: Modify configuration properties for a project. Only the specified keys will be updated.
# @param config
# Configuration properties for a project.
# @param jobs
# Rundeck jobs related to a project.
#
define rundeck::config::project (
Enum['set', 'update'] $update_method = 'update',
Hash[String, String] $config = {
'project.description' => "${name} project",
'project.label' => $name,
Expand All @@ -28,6 +29,8 @@
'project.execution.history.cleanup.schedule' => '0 0 0 1/1 * ? *',
'project.jobs.gui.groupExpandLevel' => '1',
},
Enum['set', 'update'] $update_method = 'update',
Hash[String, Rundeck::Job] $jobs = {},
) {
include rundeck::cli

Expand Down Expand Up @@ -60,4 +63,22 @@
unless => $_project_diff,
;
}

$jobs.each |$_name, $_attr| {
if $_attr['ensure'] == 'absent' {
exec { "Remove rundeck 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}'",
}
}

exec { "Create/update rundeck job: ${_name}":
command => "rd jobs load -r -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']}",
}
}
}
17 changes: 9 additions & 8 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,15 @@

if $manage_cli {
class { 'rundeck::cli':
manage_repo => false,
version => $cli_version,
url => $rundeck::config::framework_config['framework.server.url'],
bypass_url => $grails_server_url,
user => $cli_user,
password => $cli_password,
token => $cli_token,
projects => $cli_projects,
manage_repo => false,
notify_conn_check => true,
version => $cli_version,
url => $rundeck::config::framework_config['framework.server.url'],
bypass_url => $grails_server_url,
user => $cli_user,
password => $cli_password,
token => $cli_token,
projects => $cli_projects,
}

Class['rundeck::service']
Expand Down
71 changes: 49 additions & 22 deletions spec/classes/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,24 @@
it { is_expected.to contain_class('apt::update').that_comes_before('Package[rundeck-cli]') }
it { is_expected.to contain_package('rundeck-cli').with(ensure: 'installed') }
it { is_expected.to contain_file('/usr/local/bin/rd_project_diff.sh').with(ensure: 'file', mode: '0755') }
it { is_expected.to contain_file('/usr/local/bin/rd_job_diff.sh').with(ensure: 'file', mode: '0755') }
end

it do
is_expected.to contain_exec('Check rundeck cli connection').with(
command: 'rd system info',
path: ['/bin', '/usr/bin', '/usr/local/bin'],
environment: [
'RD_FORMAT=json',
'RD_URL=http://localhost:4440',
'RD_BYPASS_URL=http://localhost:4440',
'RD_USER=admin',
'RD_PASSWORD=admin',
],
tries: 60,
try_sleep: 5,
unless: 'rd system info &> /dev/null'
).that_requires('Package[rundeck-cli]')
end
it do
is_expected.to contain_exec('Check rundeck cli connection').with(
command: 'rd system info',
path: ['/bin', '/usr/bin', '/usr/local/bin'],
environment: [
'RD_FORMAT=json',
'RD_URL=http://localhost:4440',
'RD_BYPASS_URL=http://localhost:4440',
'RD_USER=admin',
'RD_PASSWORD=admin',
],
tries: 60,
try_sleep: 5,
unless: 'rd system info &> /dev/null'
).that_requires('Package[rundeck-cli]')
end
end

Expand Down Expand Up @@ -92,12 +93,28 @@
'project.description' => 'This is My rundeck project',
'project.disable.executions' => 'false',
},
'jobs' => {
'MyJob1' => {
'path' => '/etc/myjob1',
'format' => 'yaml',
},
'MyJob2' => {
'path' => '/etc/myjob2',
'format' => 'xml',
},
},
},
'TestProject' => {
'config' => {
'project.description' => 'This is a rundeck test project',
'project.disable.schedule' => 'false',
},
'jobs' => {
'TestJob1' => {
'path' => '/etc/testjob1',
'format' => 'yaml',
},
},
},
},
}
Expand All @@ -109,24 +126,34 @@
config: {
'project.description' => 'This is My rundeck project',
'project.disable.executions' => 'false',
},
jobs: {
'MyJob1' => {
'path' => '/etc/myjob1',
'format' => 'yaml',
},
'MyJob2' => {
'path' => '/etc/myjob2',
'format' => 'xml',
},
}
)
end

it { is_expected.to contain_exec('Create rundeck project: MyProject') }
it { is_expected.to contain_exec('Manage rundeck project: MyProject') }

it do
is_expected.to contain_rundeck__config__project('TestProject').with(
config: {
'project.description' => 'This is a rundeck test project',
'project.disable.schedule' => 'false',
},
jobs: {
'TestJob1' => {
'path' => '/etc/testjob1',
'format' => 'yaml',
}
}
)
end

it { is_expected.to contain_exec('Create rundeck project: TestProject') }
it { is_expected.to contain_exec('Manage rundeck project: TestProject') }
end
end
end
Expand Down

0 comments on commit 59880bb

Please sign in to comment.