Skip to content

Commit

Permalink
Use cli class as a separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
Joris29 committed Jan 15, 2024
1 parent 1ab15ca commit bbcd1d5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
18 changes: 9 additions & 9 deletions manifests/cli.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#
class rundeck::cli (
Hash $repo_config,
Boolean $manage_repo = false,
String[1] $package_ensure = $rundeck::cli_package_ensure,
Stdlib::HTTPUrl $url = $rundeck::config::framework_config['framework.server.url'],
Stdlib::HTTPUrl $bypass_url = $rundeck::grails_server_url,
String[1] $user = $rundeck::cli_user,
String[1] $password = $rundeck::cli_password,
Optional[String[8]] $token = $rundeck::cli_token,
Optional[Hash] $projects = $rundeck::projects,
Boolean $manage_repo = true,
String[1] $version = 'installed',
Stdlib::HTTPUrl $url = 'http://localhost:4440',
Stdlib::HTTPUrl $bypass_url = "http://${facts['networking']['fqdn']}:4440",
String[1] $user = 'admin',
Variant[String[1], Sensitive[String[1]]] $password = 'admin',
Optional[Variant[String[8], Sensitive[String[8]]]] $token = undef,
Hash $projects = {},
) {
ensure_resource('package', 'jq', { 'ensure' => 'present' })

Expand Down Expand Up @@ -42,7 +42,7 @@
}

package { 'rundeck-cli':
ensure => $package_ensure,
ensure => $version,
}

file { '/usr/local/bin/rd_project_diff.sh':
Expand Down
19 changes: 16 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,32 @@
Boolean $service_notify = true,
Optional[String[1]] $service_config = undef,
Optional[String[1]] $service_script = undef,
String[1] $cli_package_ensure = 'installed',
Boolean $manage_cli = true,
String[1] $cli_version = 'installed',
String[1] $cli_user = 'admin',
String[1] $cli_password = 'admin',
Optional[String[8]] $cli_token = undef,
Hash $projects = {},
Hash $cli_projects = {},
) {
validate_rd_policy($admin_policies)
validate_rd_policy($api_policies)

contain rundeck::install
contain rundeck::config
contain rundeck::service
contain rundeck::cli

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

if $service_notify {
Class['rundeck::install']
Expand Down
29 changes: 26 additions & 3 deletions spec/classes/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,34 @@
facts
end

context 'without any parameters test class' do
let(:params) { {} }

context 'with default parameters' do
it { is_expected.not_to compile }
end

context 'with manage_repo => true' do
let(:params) do
{
'manage_repo' => true,
}
end

case facts[:os]['family']
when 'RedHat'
it do
is_expected.to contain_yumrepo('rundeck').with(
baseurl: 'https://packages.rundeck.com/pagerduty/rundeck/rpm_any/rpm_any/$basearch',
repo_gpgcheck: 1,
gpgcheck: 0,
enabled: 1,
gpgkey: 'https://packages.rundeck.com/pagerduty/rundeck/gpgkey'
).that_comes_before('Package[rundeck]')
end
when 'Debian'
it { is_expected.to contain_apt__source('rundeck').with_location('https://packages.rundeck.com/pagerduty/rundeck/any') }
it { is_expected.to contain_class('apt::update').that_comes_before('Package[rundeck]') }
it { is_expected.to contain_package('rundeck').that_notifies('Class[rundeck::service]') }
end
end
end
end
end

0 comments on commit bbcd1d5

Please sign in to comment.