Skip to content

Commit

Permalink
Add SCM config options to project define
Browse files Browse the repository at this point in the history
  • Loading branch information
Joris VAN ACOLEYEN committed Aug 1, 2024
1 parent 8ccc924 commit 79be90f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
8 changes: 8 additions & 0 deletions files/rd_scm_diff.sh
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)"
3 changes: 3 additions & 0 deletions manifests/cli.pp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
'/usr/local/bin/rd_job_diff.sh':
content => file('rundeck/rd_job_diff.sh'),
;
'/usr/local/bin/rd_scm_diff.sh':
content => file('rundeck/rd_scm_diff.sh'),
;
}

$_default_env_vars = [
Expand Down
73 changes: 73 additions & 0 deletions manifests/config/project.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
# 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_import_config
# A hash of name value pairs representing properties for the scm-import.json file.
# @param scm_export_config
# A hash of name value pairs representing properties for the scm-export.json file
#
define rundeck::config::project (
Enum['absent', 'present'] $ensure = 'present',
Expand All @@ -34,6 +44,11 @@
},
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_import_config = undef,
Optional[Rundeck::Scm] $scm_export_config = undef,
) {
include rundeck::cli

Expand Down Expand Up @@ -92,5 +107,63 @@
}
}
}

if $scm_import_config {
ensure_resource('file', "${projects_dir}/${name}",
{
'ensure' => 'directory',
'owner' => $owner,
'group' => $group,
'mode' => '0755'
}
)

file { "${projects_dir}/${name}/scm-import.json":
ensure => file,
owner => $owner,
group => $group,
mode => '0644',
content => stdlib::to_json($scm_import_config),
}

$_command = "rd projects scm setup -p '${name}' -i import -t ${scm_import_config['type']} -f ${projects_dir}/${name}/scm-import.json"

exec { "Setup/update SCM import config for ${name}":
command => "env RD_FORMAT=default ${_command}",
path => ['/bin', '/usr/bin', '/usr/local/bin'],
environment => $rundeck::cli::environment,
unless => "rd_scm_diff.sh ${projects_dir} '${name}' import",
require => File["${projects_dir}/${name}/scm-import.json"],
}
}

if $scm_export_config {
ensure_resource('file', "${projects_dir}/${name}",
{
'ensure' => 'directory',
'owner' => $owner,
'group' => $group,
'mode' => '0755'
}
)

file { "${projects_dir}/${name}/scm-export.json":
ensure => file,
owner => $owner,
group => $group,
mode => '0644',
content => stdlib::to_json($scm_export_config),
}

$_command = "rd projects scm setup -p '${name}' -i export -t ${scm_export_config['type']} -f ${projects_dir}/${name}/scm-export.json"

exec { "Setup/update SCM export config for ${name}":
command => "env RD_FORMAT=default ${_command}",
path => ['/bin', '/usr/bin', '/usr/local/bin'],
environment => $rundeck::cli::environment,
unless => "rd_scm_diff.sh ${projects_dir} '${name}' export",
require => File["${projects_dir}/${name}/scm-export.json"],
}
}
}
}
5 changes: 5 additions & 0 deletions types/scm.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @summary Rundeck project type.
type Rundeck::Scm = Struct[{
'type' => String[1],
'config' => Hash[String[1], String],
}]

0 comments on commit 79be90f

Please sign in to comment.