Defined Type: rundeck::config::project

Defined in:
manifests/config/project.pp

Summary

This define will manage projects and jobs.

Overview

Examples:

Basic usage.

rundeck::config::project { 'MyProject':
  config => {
    'project.description'      => 'My test project',
    'project.disable.schedule' => 'false',
  },
}

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',
    },
  },
}

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://myuser@example.com/example/example.git',
        'filePattern'           => '*.xml',
        'useFilePattern'        => 'true',
        'pathTemplate'          => "\${job.id}.\${config.format}",
        'importUuidBehavior'    => 'preserve',
        'sshPrivateKeyPath'     => '',
        'fetchAutomatically'    => 'true',
        'pullAutomatically'     => 'true',
      },
    },
  },
}

Parameters:

  • ensure (Enum['absent', 'present']) (defaults to: 'present')

    Whether or not the project should be present.

  • config (Hash[String, String]) (defaults to: { 'project.description' => "${name} project", 'project.label' => $name, 'project.disable.executions' => 'false', 'project.disable.schedule' => 'false', 'project.execution.history.cleanup.batch' => '500', 'project.execution.history.cleanup.enabled' => 'true', 'project.execution.history.cleanup.retention.days' => '60', 'project.execution.history.cleanup.retention.minimum' => '50', 'project.execution.history.cleanup.schedule' => '0 0 0 1/1 * ? *', 'project.jobs.gui.groupExpandLevel' => '1', })

    Configuration properties for a project.

  • update_method (Enum['set', 'update']) (defaults to: '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.

  • jobs (Hash[String, Rundeck::Job]) (defaults to: {})

    Rundeck jobs related to a project.

  • owner (String[1]) (defaults to: 'rundeck')

    The user that rundeck is installed as.

  • group (String[1]) (defaults to: 'rundeck')

    The group permission that rundeck is installed as.

  • projects_dir (Stdlib::Absolutepath) (defaults to: '/var/lib/rundeck/projects')

    Directory where some project config will be stored.

  • scm_config (Optional[Rundeck::Scm]) (defaults to: undef)

    A hash of name value pairs representing properties for the scm.json file.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'manifests/config/project.pp', line 80

define rundeck::config::project (
  Enum['absent', 'present'] $ensure = 'present',
  Hash[String, String] $config = {
    'project.description'                                 => "${name} project",
    'project.label'                                       => $name,
    'project.disable.executions'                          => 'false',
    'project.disable.schedule'                            => 'false',
    'project.execution.history.cleanup.batch'             => '500',
    'project.execution.history.cleanup.enabled'           => 'true',
    'project.execution.history.cleanup.retention.days'    => '60',
    'project.execution.history.cleanup.retention.minimum' => '50',
    '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 = {},
  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

  $_default_cfg = {
    'project.name' => $name,
  }

  $_final_cfg = $config + $_default_cfg

  $_cmd_line_cfg = $_final_cfg.map |$_k, $_v| {
    "--${_k}=${_v}"
  }

  $_project_diff = $update_method ? {
    'set'   => "rd_project_diff.sh '${name}' ${update_method} '${_final_cfg.to_json}'",
    default => "rd_project_diff.sh '${name}' ${update_method} '${_final_cfg.to_json}' '${_final_cfg.keys}'",
  }

  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,
      onlyif      => "rd projects info -p '${name}'",
    }
  } else {
    exec {
      default:
        path        => ['/bin', '/usr/bin', '/usr/local/bin'],
        environment => $rundeck::cli::environment,
        ;
      "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']}",
        }
      }
    }

    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"],
        }
      }
    }
  }
}