Skip to content

Commit f0d3223

Browse files
authored
Merge pull request #70 from treydock/redhat-only
Allow the ca package to be excluded to support registering with RedHat
2 parents 34c8908 + d3c2b8c commit f0d3223

File tree

4 files changed

+71
-51
lines changed

4 files changed

+71
-51
lines changed

data/defaults.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ subscription_manager::package_names:
44
- 'subscription-manager'
55
subscription_manager::service_name: 'goferd'
66
subscription_manager::service_status: 'running'
7+
subscription_manager::ca_package: true
78
subscription_manager::ca_package_prefix: 'katello-ca-consumer-'
89
subscription_manager::autosubscribe: false
910
subscription_manager::force: false

manifests/init.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
#
122122
class subscription_manager (
123123
Array[String] $package_names = ['subscription-manager'],
124+
Boolean $ca_package = true,
124125
String $ca_package_prefix = 'katello-ca-consumer-',
125126
String $service_name = 'goferd',
126127
Enum['running','stopped', 'disabled', 'enabled'] $service_status = 'running',

manifests/install.pp

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -45,62 +45,63 @@
4545
-> Package[ $::subscription_manager::package_names ]
4646
}
4747

48-
# shorten several really long names
49-
$_ca = $::facts['rhsm_ca_name']
50-
$_id = $::facts['rhsm_identity']
51-
$_prefix = $::subscription_manager::ca_package_prefix
52-
$_hostname = $::subscription_manager::server_hostname
53-
$_pkg = "${_prefix}${_hostname}" # 80-column puppet-lint limit workaround
48+
if $::subscription_manager::ca_package {
49+
# shorten several really long names
50+
$_ca = $::facts['rhsm_ca_name']
51+
$_id = $::facts['rhsm_identity']
52+
$_prefix = $::subscription_manager::ca_package_prefix
53+
$_hostname = $::subscription_manager::server_hostname
54+
$_pkg = "${_prefix}${_hostname}" # 80-column puppet-lint limit workaround
5455

55-
# four scenarios
56-
# I. never registered
57-
# - no ca_name
58-
# - no identity
59-
# - just install normally
60-
package { $_pkg:
61-
ensure => 'present',
62-
provider => 'rpm',
63-
source =>
64-
"http://${_hostname}/pub/${_prefix}latest.noarch.rpm",
65-
}
56+
# four scenarios
57+
# I. never registered
58+
# - no ca_name
59+
# - no identity
60+
# - just install normally
61+
package { $_pkg:
62+
ensure => 'present',
63+
provider => 'rpm',
64+
source =>
65+
"http://${_hostname}/pub/${_prefix}latest.noarch.rpm",
66+
}
6667

67-
# II. registered to correct server
68-
# - ca_name == server_hostname
69-
# - identity is set
70-
# - do nothing new, let puppet idempotency handle it
68+
# II. registered to correct server
69+
# - ca_name == server_hostname
70+
# - identity is set
71+
# - do nothing new, let puppet idempotency handle it
7172

72-
# III. registered to different server
73-
# - ca_name != server_hostname
74-
# - identity may or may not be set
75-
# - remove old, install new
76-
if $_ca != '' and $_ca != undef {
77-
# an SSL Certificate Authority is detected
78-
# does it match server_hostname (aka _suffix for the package)
79-
if $_ca != $_hostname {
80-
# but CA is changing
81-
# remove the old package
82-
package { "${_prefix}${_ca}": ensure => 'absent', }
83-
Package["${_prefix}${_ca}"] -> Package[$_pkg]
73+
# III. registered to different server
74+
# - ca_name != server_hostname
75+
# - identity may or may not be set
76+
# - remove old, install new
77+
if $_ca != '' and $_ca != undef {
78+
# an SSL Certificate Authority is detected
79+
# does it match server_hostname (aka _suffix for the package)
80+
if $_ca != $_hostname {
81+
# but CA is changing
82+
# remove the old package
83+
package { "${_prefix}${_ca}": ensure => 'absent', }
84+
Package["${_prefix}${_ca}"] -> Package[$_pkg]
85+
}
8486
}
85-
}
8687

87-
# IV. registered to same server but CA is bad
88-
# - ca_name == server_hostname
89-
# - identity is not set
90-
# - reinstall (this requires a pupetlabs-transition)
91-
# This case is meant to prevent extra regitrations on pre-6.2 Satellite
92-
if ((($_id == '' or $_id == undef) and $_ca == $_hostname) or
93-
($_ca == $_hostname and $::subscription_manager::force == true )) {
94-
$_attributes = {
95-
'ensure' => 'absent',
96-
'provider' => 'rpm',
97-
'install_options' => [ '--force', '--nodeps' ],
98-
}
99-
transition {'purge-bad-rhsm_ca-package':
100-
resource => Package[$_pkg],
101-
attributes => $_attributes,
102-
prior_to => Package[$_pkg],
88+
# IV. registered to same server but CA is bad
89+
# - ca_name == server_hostname
90+
# - identity is not set
91+
# - reinstall (this requires a pupetlabs-transition)
92+
# This case is meant to prevent extra regitrations on pre-6.2 Satellite
93+
if ((($_id == '' or $_id == undef) and $_ca == $_hostname) or
94+
($_ca == $_hostname and $::subscription_manager::force == true )) {
95+
$_attributes = {
96+
'ensure' => 'absent',
97+
'provider' => 'rpm',
98+
'install_options' => [ '--force', '--nodeps' ],
99+
}
100+
transition {'purge-bad-rhsm_ca-package':
101+
resource => Package[$_pkg],
102+
attributes => $_attributes,
103+
prior_to => Package[$_pkg],
104+
}
103105
}
104106
}
105-
106107
}

spec/classes/subscription_manager_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@
129129
it { is_expected.to contain_rhsm_config('/etc/rhsm/rhsm.conf') }
130130
it { is_expected.to contain_transition('purge-bad-rhsm_ca-package') }
131131
end
132+
describe "subscription_manager class without ca_package on #{os}" do
133+
let(:facts) do
134+
facts.merge({
135+
:rhsm_ca_name => 'foo',
136+
:rhsm_identity => ''# no rhsm_register without force if identity is valid
137+
})
138+
end
139+
let(:params) {{
140+
:activationkey => 'foo-bar',
141+
:server_hostname => 'foo',
142+
:ca_package => false,
143+
}}
144+
it { is_expected.to compile.with_all_deps }
145+
it_behaves_like 'a supported operating system'
146+
it { is_expected.to_not contain_package('katello-ca-consumer-foo') }
147+
it { is_expected.to_not contain_transition('purge-bad-rhsm_ca-package') }
148+
end
132149
describe "subscription_manager class with an identity on #{os}" do
133150
let(:facts) do
134151
facts.merge(rhsm_ca_name: 'subscription.rhn.redhat.com',

0 commit comments

Comments
 (0)