-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #546 from Joris29/scm
Add scm config options to project define
- Loading branch information
Showing
9 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
* [`Rundeck::Loglevel`](#Rundeck--Loglevel): Rundeck log level type. | ||
* [`Rundeck::Mail_config`](#Rundeck--Mail_config): Rundeck mail config type. | ||
* [`Rundeck::Project`](#Rundeck--Project): Rundeck project type. | ||
* [`Rundeck::Scm`](#Rundeck--Scm): Rundeck scm type. | ||
|
||
## Classes | ||
|
||
|
@@ -1008,6 +1009,63 @@ rundeck::config::project { 'MyProject': | |
} | ||
``` | ||
|
||
##### Advanced usage with jobs. | ||
|
||
```puppet | ||
rundeck::config::project { 'MyProject': | ||
config => { | ||
'project.description' => 'My test project', | ||
'project.disable.schedule' => 'false', | ||
}, | ||
jobs => { | ||
'MyJob1' => { | ||
'path' => '/etc/myjob1', | ||
'format' => 'yaml', | ||
}, | ||
'MyJob2' => { | ||
'path' => '/etc/myjob2', | ||
'format' => 'xml', | ||
}, | ||
'DeleteJob1' => { | ||
'ensure' => 'absent', | ||
'path' => '/etc/testjob1', | ||
'format' => 'yaml', | ||
}, | ||
}, | ||
} | ||
``` | ||
|
||
##### Advanced usage with scm_config. | ||
|
||
```puppet | ||
rundeck::config::project { 'MyProject': | ||
config => { | ||
'project.description' => 'My test project', | ||
'project.disable.schedule' => 'false', | ||
}, | ||
scm_config => { | ||
'import' => { | ||
'type' => 'git-import', | ||
'config' => { | ||
'strictHostKeyChecking' => 'yes', | ||
'gitPasswordPath' => 'keys/example-access-token', | ||
'format' => 'xml', | ||
'dir' => '/var/lib/rundeck/projects/MyProject/ScmImport', | ||
'branch' => 'master', | ||
'url' => 'https://[email protected]/example/example.git', | ||
'filePattern' => '*.xml', | ||
'useFilePattern' => 'true', | ||
'pathTemplate' => "\${job.id}.\${config.format}", | ||
'importUuidBehavior' => 'preserve', | ||
'sshPrivateKeyPath' => '', | ||
'fetchAutomatically' => 'true', | ||
'pullAutomatically' => 'true', | ||
}, | ||
}, | ||
}, | ||
} | ||
``` | ||
|
||
#### Parameters | ||
|
||
The following parameters are available in the `rundeck::config::project` defined type: | ||
|
@@ -1016,6 +1074,10 @@ The following parameters are available in the `rundeck::config::project` defined | |
* [`config`](#-rundeck--config--project--config) | ||
* [`update_method`](#-rundeck--config--project--update_method) | ||
* [`jobs`](#-rundeck--config--project--jobs) | ||
* [`owner`](#-rundeck--config--project--owner) | ||
* [`group`](#-rundeck--config--project--group) | ||
* [`projects_dir`](#-rundeck--config--project--projects_dir) | ||
* [`scm_config`](#-rundeck--config--project--scm_config) | ||
|
||
##### <a name="-rundeck--config--project--ensure"></a>`ensure` | ||
|
||
|
@@ -1065,6 +1127,38 @@ Rundeck jobs related to a project. | |
|
||
Default value: `{}` | ||
|
||
##### <a name="-rundeck--config--project--owner"></a>`owner` | ||
|
||
Data type: `String[1]` | ||
|
||
The user that rundeck is installed as. | ||
|
||
Default value: `'rundeck'` | ||
|
||
##### <a name="-rundeck--config--project--group"></a>`group` | ||
|
||
Data type: `String[1]` | ||
|
||
The group permission that rundeck is installed as. | ||
|
||
Default value: `'rundeck'` | ||
|
||
##### <a name="-rundeck--config--project--projects_dir"></a>`projects_dir` | ||
|
||
Data type: `Stdlib::Absolutepath` | ||
|
||
Directory where some project config will be stored. | ||
|
||
Default value: `'/var/lib/rundeck/projects'` | ||
|
||
##### <a name="-rundeck--config--project--scm_config"></a>`scm_config` | ||
|
||
Data type: `Optional[Rundeck::Scm]` | ||
|
||
A hash of name value pairs representing properties for the scm.json file. | ||
|
||
Default value: `undef` | ||
|
||
### <a name="rundeck--config--secret"></a>`rundeck::config::secret` | ||
|
||
This define will manage secrets in key storage. | ||
|
@@ -1261,3 +1355,31 @@ Struct[{ | |
}] | ||
``` | ||
|
||
### <a name="Rundeck--Scm"></a>`Rundeck::Scm` | ||
|
||
Rundeck scm type. | ||
|
||
Alias of | ||
|
||
```puppet | ||
Variant[Struct[{ | ||
'import' => Struct[{ | ||
'type' => String[1], | ||
'config' => Hash[String[1], String], | ||
}], | ||
Optional['export'] => Struct[{ | ||
'type' => String[1], | ||
'config' => Hash[String[1], String], | ||
}], | ||
}], Struct[{ | ||
'export' => Struct[{ | ||
'type' => String[1], | ||
'config' => Hash[String[1], String], | ||
}], | ||
Optional['import'] => Struct[{ | ||
'type' => String[1], | ||
'config' => Hash[String[1], String], | ||
}], | ||
}]] | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
# THIS FILE IS MANAGED BY PUPPET | ||
|
||
projects_dir="$1" | ||
project="$2" | ||
interaction="$3" | ||
|
||
bash -c "diff <(rd projects scm config -p '$project' -i $interaction | jq .config -S) <(cat $projects_dir/$project/scm-import.json | jq .config -S)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,57 @@ | |
# }, | ||
# } | ||
# | ||
# @example Advanced usage with jobs. | ||
# rundeck::config::project { 'MyProject': | ||
# config => { | ||
# 'project.description' => 'My test project', | ||
# 'project.disable.schedule' => 'false', | ||
# }, | ||
# jobs => { | ||
# 'MyJob1' => { | ||
# 'path' => '/etc/myjob1', | ||
# 'format' => 'yaml', | ||
# }, | ||
# 'MyJob2' => { | ||
# 'path' => '/etc/myjob2', | ||
# 'format' => 'xml', | ||
# }, | ||
# 'DeleteJob1' => { | ||
# 'ensure' => 'absent', | ||
# 'path' => '/etc/testjob1', | ||
# 'format' => 'yaml', | ||
# }, | ||
# }, | ||
# } | ||
# | ||
# @example Advanced usage with scm_config. | ||
# rundeck::config::project { 'MyProject': | ||
# config => { | ||
# 'project.description' => 'My test project', | ||
# 'project.disable.schedule' => 'false', | ||
# }, | ||
# scm_config => { | ||
# 'import' => { | ||
# 'type' => 'git-import', | ||
# 'config' => { | ||
# 'strictHostKeyChecking' => 'yes', | ||
# 'gitPasswordPath' => 'keys/example-access-token', | ||
# 'format' => 'xml', | ||
# 'dir' => '/var/lib/rundeck/projects/MyProject/ScmImport', | ||
# 'branch' => 'master', | ||
# 'url' => 'https://[email protected]/example/example.git', | ||
# 'filePattern' => '*.xml', | ||
# 'useFilePattern' => 'true', | ||
# 'pathTemplate' => "\${job.id}.\${config.format}", | ||
# 'importUuidBehavior' => 'preserve', | ||
# 'sshPrivateKeyPath' => '', | ||
# 'fetchAutomatically' => 'true', | ||
# 'pullAutomatically' => 'true', | ||
# }, | ||
# }, | ||
# }, | ||
# } | ||
# | ||
# @param ensure | ||
# Whether or not the project should be present. | ||
# @param config | ||
|
@@ -17,6 +68,14 @@ | |
# update: Modify configuration properties for a project. Only the specified keys will be updated. | ||
# @param jobs | ||
# Rundeck jobs related to a project. | ||
# @param owner | ||
# The user that rundeck is installed as. | ||
# @param group | ||
# The group permission that rundeck is installed as. | ||
# @param projects_dir | ||
# Directory where some project config will be stored. | ||
# @param scm_config | ||
# A hash of name value pairs representing properties for the scm.json file. | ||
# | ||
define rundeck::config::project ( | ||
Enum['absent', 'present'] $ensure = 'present', | ||
|
@@ -34,6 +93,10 @@ | |
}, | ||
Enum['set', 'update'] $update_method = 'update', | ||
Hash[String, Rundeck::Job] $jobs = {}, | ||
String[1] $owner = 'rundeck', | ||
String[1] $group = 'rundeck', | ||
Stdlib::Absolutepath $projects_dir = '/var/lib/rundeck/projects', | ||
Optional[Rundeck::Scm] $scm_config = undef, | ||
) { | ||
include rundeck::cli | ||
|
||
|
@@ -92,5 +155,42 @@ | |
} | ||
} | ||
} | ||
|
||
if $scm_config { | ||
ensure_resource('file', "${projects_dir}/${name}", | ||
{ | ||
'ensure' => 'directory', | ||
'owner' => $owner, | ||
'group' => $group, | ||
'mode' => '0755' | ||
} | ||
) | ||
|
||
$scm_config.each |$integration, $config| { | ||
file { "${projects_dir}/${name}/scm-${integration}.json": | ||
ensure => file, | ||
owner => $owner, | ||
group => $group, | ||
mode => '0644', | ||
content => stdlib::to_json($config), | ||
} | ||
|
||
$_command = [ | ||
'rd projects scm setup', | ||
"-p '${name}'", | ||
"-i ${integration}", | ||
"-t ${config['type']}", | ||
"-f ${projects_dir}/${name}/scm-${integration}.json", | ||
].join(' ') | ||
|
||
exec { "Setup/update SCM ${integration} config for rundeck project: ${name}": | ||
command => $_command, | ||
path => ['/bin', '/usr/bin', '/usr/local/bin'], | ||
environment => $rundeck::cli::environment, | ||
unless => "rd_scm_diff.sh ${projects_dir} '${name}' ${integration}", | ||
require => File["${projects_dir}/${name}/scm-${integration}.json"], | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,74 @@ | |
it { is_expected.to contain_exec('(MyJobProject) Create/update job: TestJob1') } | ||
it { is_expected.to contain_exec('(MyJobProject) Remove job: DeleteJob1') } | ||
end | ||
|
||
context 'Add rundeck project: TestSCM with scm config' do | ||
name = 'TestSCM' | ||
|
||
let(:title) { name } | ||
let(:params) do | ||
{ | ||
scm_config: { | ||
'import' => { | ||
'type' => 'git-import', | ||
'config' => { | ||
'strictHostKeyChecking' => 'yes', | ||
'gitPasswordPath' => 'keys/example-access-token', | ||
'format' => 'xml', | ||
'dir' => '/var/lib/rundeck/projects/MyProject/ScmImport', | ||
'branch' => 'master', | ||
'url' => 'https://[email protected]/example/example.git', | ||
'filePattern' => '*.xml', | ||
'useFilePattern' => 'true', | ||
'pathTemplate' => '${job.id}.${config.format}', | ||
'importUuidBehavior' => 'preserve', | ||
'sshPrivateKeyPath' => '', | ||
'fetchAutomatically' => 'true', | ||
'pullAutomatically' => 'true', | ||
}, | ||
}, | ||
}, | ||
} | ||
end | ||
|
||
it { is_expected.to contain_exec('Create rundeck project: TestSCM') } | ||
it { is_expected.to contain_exec('Manage rundeck project: TestSCM') } | ||
it { is_expected.to contain_file('/var/lib/rundeck/projects/TestSCM').with(ensure: 'directory', owner: 'rundeck', group: 'rundeck', mode: '0755') } | ||
it { is_expected.to contain_file('/var/lib/rundeck/projects/TestSCM/scm-import.json').with(ensure: 'file', owner: 'rundeck', group: 'rundeck', mode: '0644') } | ||
it { is_expected.to contain_exec('Setup/update SCM import config for rundeck project: TestSCM').that_requires('File[/var/lib/rundeck/projects/TestSCM/scm-import.json]') } | ||
end | ||
|
||
context 'Add rundeck project: TestWrongSCM with wrong scm config' do | ||
name = 'TestWrongSCM' | ||
|
||
let(:title) { name } | ||
let(:params) do | ||
{ | ||
scm_config: { | ||
'wrong_key' => { | ||
'type' => 'git-import', | ||
'config' => { | ||
'strictHostKeyChecking' => 'yes', | ||
'gitPasswordPath' => 'keys/example-access-token', | ||
'format' => 'xml', | ||
'dir' => '/var/lib/rundeck/projects/MyProject/ScmImport', | ||
'branch' => 'master', | ||
'url' => 'https://[email protected]/example/example.git', | ||
'filePattern' => '*.xml', | ||
'useFilePattern' => 'true', | ||
'pathTemplate' => '${job.id}.${config.format}', | ||
'importUuidBehavior' => 'preserve', | ||
'sshPrivateKeyPath' => '', | ||
'fetchAutomatically' => 'true', | ||
'pullAutomatically' => 'true', | ||
}, | ||
}, | ||
}, | ||
} | ||
end | ||
|
||
it { is_expected.not_to compile } | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.