Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate configuration of SCM export properties in a project #218

Merged
merged 1 commit into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion manifests/config/project.pp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
$node_executor_settings = {},
$projects_dir = undef,
$resource_sources = $rundeck::resource_sources,
$scm_import_properties = $rundeck::scm_import_properties,
$scm_import_properties = {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do blank hashes/arrays in parameterized class variables still break hiera?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jyaworski - yes, they break in the current implementation. In the template, the hash is iterated over like this:

<%- @scm_export_properties.sort.each do |k,v| -%>
<%= k %> = <%= v %>
<%- end -%>

If the hash is empty (which it may be if the user does not have a need to configure the SCM for a certain project), provisioning would fail on a null hash if it was not defaulted to '{}' here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is that hiera's automatic lookups are known to fail on blank array defaults. Do they fail with blank hash defaults?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null hash values or hashes with keys that have null values work fine.

$scm_export_properties = {},
$ssh_keypath = undef,
$user = $rundeck::user,
) {
Expand Down Expand Up @@ -85,6 +86,7 @@
$project_dir = "${projects_dir_real}/${name}"
$properties_file = "${project_dir}/etc/project.properties"
$scm_import_properties_file = "${project_dir}/etc/scm-import.properties"
$scm_export_properties_file = "${project_dir}/etc/scm-export.properties"

file { $project_dir :
ensure => directory,
Expand All @@ -110,6 +112,15 @@
replace => false,
}

file { $scm_export_properties_file:
ensure => present,
content => template('rundeck/scm-export.properties.erb'),
owner => $user,
group => $group,
require => File["${project_dir}/etc"],
replace => false,
}

file { "${project_dir}/var":
ensure => directory,
owner => $user,
Expand Down
1 change: 0 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@
$truststore_password = 'adminadmin'

$resource_sources = {}
$scm_import_properties = {}
$gui_config = {}

$preauthenticated_config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@
'scm.import.username' => '',
'scm.import.roles.count' => '3',
'scm.import.trackedItems.count' => '0'
},
'scm_export_properties' => {
'scm.export.enabled' => 'false',
'scm.export.config.format' => 'yaml',
'scm.export.config.dir' => '/var/lib/rundeck/projects/project_1/scm',
'scm.export.config.url' => 'git.repo.com/project_1.jobs.git',
'scm.export.config.branch' => 'master',
'scm.export.config.pathTemplate' => '{job.project}/${job.group}${job.name}-${job.id}.${config.format}',
'scm.export.config.strictHostKeyChecking' => 'no',
'scm.export.config.gitPasswordPath' => '',
'scm.export.config.sshPrivateKeyPath' => 'keys/${project}/users/scm/${user.login}.private',
'scm.export.roles.count' => '2',
'scm.export.roles.1' => 'user',
'scm.export.type' => 'git-export',
'scm.export.username' => '${user.username}',
'scm.export.config.committerName' => '${user.fullName}',
'scm.export.config.committerEmail' => '${user.email}'
}
}
}
Expand All @@ -47,5 +64,11 @@
expect(content).to include("#{key} = #{value}")
end
end
project_hash['project_1']['scm_export_properties'].each do |key, value|
it 'should generate valid content for scm-export.properties' do
content = catalogue.resource('file', '/var/lib/rundeck/projects/project_1/etc/scm-export.properties')[:content]
expect(content).to include("#{key} = #{value}")
end
end
end
end
1 change: 0 additions & 1 deletion spec/defines/config/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
},
:file_copier_provider => 'jsch-scp',
:resource_sources => {},
:scm_import_properties => {},
:node_executor_provider => 'jsch-ssh',
:user => 'rundedck',
:group => 'rundeck'
Expand Down
3 changes: 3 additions & 0 deletions templates/scm-export.properties.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%- @scm_export_properties.sort.each do |k,v| -%>
<%= k %> = <%= v %>
<%- end -%>