diff --git a/REFERENCE.md b/REFERENCE.md
index 88726da4..32877add 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -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
@@ -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)
@@ -722,6 +724,14 @@ Whether to manage the cli package repository.
Default value: `true`
+##### `notify_conn_check`
+
+Data type: `Boolean`
+
+Wheter to notify the cli connection check if rundeck service changes.
+
+Default value: `false`
+
##### `version`
Data type: `String[1]`
@@ -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)
-
-##### `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)
##### `config`
@@ -991,6 +993,23 @@ Default value:
}
```
+##### `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'`
+
+##### `jobs`
+
+Data type: `Hash[String, Rundeck::Job]`
+
+Rundeck jobs related to a project.
+
+Default value: `{}`
+
## Functions
### `validate_rd_policy`
@@ -1038,6 +1057,19 @@ Struct[{
}]
```
+### `Rundeck::Job`
+
+Rundeck job type.
+
+Alias of
+
+```puppet
+Struct[{
+ 'path' => Stdlib::Absolutepath,
+ 'format' => Enum['yaml', 'xml', 'json'],
+}]
+```
+
### `Rundeck::Key_storage_config`
Rundeck key storage config type.
@@ -1080,14 +1112,15 @@ Struct[{
### `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],
}]
```
diff --git a/files/rd_job_diff.sh b/files/rd_job_diff.sh
new file mode 100644
index 00000000..8ed7c3b5
--- /dev/null
+++ b/files/rd_job_diff.sh
@@ -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
diff --git a/manifests/cli.pp b/manifests/cli.pp
index c44a0588..c01903e9 100644
--- a/manifests/cli.pp
+++ b/manifests/cli.pp
@@ -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
@@ -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',
@@ -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 {
@@ -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 = [
diff --git a/manifests/config/project.pp b/manifests/config/project.pp
index d2922e26..a8f1a5b1 100644
--- a/manifests/config/project.pp
+++ b/manifests/config/project.pp
@@ -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,
@@ -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
@@ -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']}",
+ }
+ }
}
diff --git a/manifests/init.pp b/manifests/init.pp
index 5ee70d7b..aa71a463 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -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']
diff --git a/spec/classes/cli_spec.rb b/spec/classes/cli_spec.rb
index 320fbffa..33dcb7e4 100644
--- a/spec/classes/cli_spec.rb
+++ b/spec/classes/cli_spec.rb
@@ -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
@@ -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',
+ },
+ },
},
},
}
@@ -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
diff --git a/spec/defines/config/project_spec.rb b/spec/defines/config/project_spec.rb
index fbac0ef0..de0a19b5 100644
--- a/spec/defines/config/project_spec.rb
+++ b/spec/defines/config/project_spec.rb
@@ -63,6 +63,64 @@
it { is_expected.to contain_exec('Create rundeck project: TestProject') }
it { is_expected.to contain_exec('Manage rundeck project: TestProject') }
end
+
+ context 'Add rundeck project: MyJobProject with jobs' do
+ name = 'MyJobProject'
+
+ let(:title) { name }
+ let(:params) do
+ {
+ config: {
+ 'project.description' => 'This is a rundeck project with jobs',
+ 'project.disable.schedule' => 'true',
+ },
+ jobs: {
+ 'MyJob1' => {
+ 'path' => '/etc/myjob1',
+ 'format' => 'yaml',
+ },
+ 'MyJob2' => {
+ 'path' => '/etc/myjob2',
+ 'format' => 'xml',
+ },
+ 'TestJob1' => {
+ 'path' => '/etc/testjob1',
+ 'format' => 'yaml',
+ },
+ },
+ }
+ end
+
+ it do
+ is_expected.to contain_rundeck__config__project('MyJobProject').with(
+ update_method: 'update',
+ config: {
+ 'project.description' => 'This is a rundeck project with jobs',
+ 'project.disable.schedule' => 'true',
+ },
+ jobs: {
+ 'MyJob1' => {
+ 'path' => '/etc/myjob1',
+ 'format' => 'yaml',
+ },
+ 'MyJob2' => {
+ 'path' => '/etc/myjob2',
+ 'format' => 'xml',
+ },
+ 'TestJob1' => {
+ 'path' => '/etc/testjob1',
+ 'format' => 'yaml',
+ }
+ }
+ )
+ end
+
+ it { is_expected.to contain_exec('Create rundeck project: MyJobProject') }
+ it { is_expected.to contain_exec('Manage rundeck project: MyJobProject') }
+ it { is_expected.to contain_exec('Create/update rundeck job: MyJob1') }
+ it { is_expected.to contain_exec('Create/update rundeck job: MyJob2') }
+ it { is_expected.to contain_exec('Create/update rundeck job: TestJob1') }
+ end
end
end
end
diff --git a/types/job.pp b/types/job.pp
new file mode 100644
index 00000000..be57febe
--- /dev/null
+++ b/types/job.pp
@@ -0,0 +1,5 @@
+# @summary Rundeck job type.
+type Rundeck::Job = Struct[{
+ 'path' => Stdlib::Absolutepath,
+ 'format' => Enum['yaml', 'xml', 'json'],
+}]
diff --git a/types/project.pp b/types/project.pp
index 493f9e27..3e46e0c4 100644
--- a/types/project.pp
+++ b/types/project.pp
@@ -1,5 +1,6 @@
-# Rundeck project config type.
+# @summary Rundeck project type.
type Rundeck::Project = Struct[{
Optional['config'] => Hash[String, String],
- Optional['update_method'] => String,
+ Optional['update_method'] => Enum['set', 'update'],
+ Optional['jobs'] => Hash[String, Rundeck::Job],
}]