Skip to content

Commit

Permalink
Merge pull request #135 from tedgarb/feature_egarbade_rhsm
Browse files Browse the repository at this point in the history
Allow the user/pw or org/key to be Deferred.
  • Loading branch information
kenyon committed Dec 19, 2023
2 parents c9b452d + 149687a commit 51b08d4
Showing 1 changed file with 46 additions and 17 deletions.
63 changes: 46 additions & 17 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -100,38 +100,54 @@
fail("${module_name}: Must provide rh_user and rh_password or org and activationkey")
}

if $rh_user {
$_user = " --username='${rh_user}'"
$_user = if $rh_user {
if $rh_user.is_a(Deferred) {
Deferred('inline_epp', [' --username="<%= $rh_user %>"', { 'rh_user' => $rh_user }])
} else {
" --username='${rh_user}'"
}
} else {
$_user = ''
''
}

if $rh_password {
$_password = " --password='${rh_password}'"
$_password = if $rh_password {
if $rh_password.is_a(Deferred) {
Deferred('inline_epp', [' --password="<%= $rh_password %>"', { 'rh_password' => $rh_password }])
} else {
" --password='${rh_password}'"
}
} else {
$_password = ''
''
}

if $org {
$_org = " --org='${org}'"
$_org = if $org {
if $org.is_a(Deferred) {
Deferred('inline_epp', [' --org="<%= $org %>"', { 'org' => $org }])
} else {
" --org='${org}'"
}
} else {
$_org = ''
''
}

if $activationkey {
$_activationkey = " --activationkey='${activationkey}'"
$_activationkey = if $activationkey {
if $activationkey.is_a(Deferred) {
Deferred('inline_epp', [' --activationkey="<%= $activationkey %>"', { 'activationkey' => $activationkey }])
} else {
" --activationkey='${activationkey}'"
}
} else {
$_activationkey = ''
''
}

if $proxy_hostname {
$proxycli = if $proxy_hostname {
if $proxy_user and $proxy_password {
$proxycli = " --proxy=${proxy_scheme}://${proxy_hostname}:${proxy_port} --proxyuser=${proxy_user} --proxypass=${proxy_password}"
" --proxy=${proxy_scheme}://${proxy_hostname}:${proxy_port} --proxyuser=${proxy_user} --proxypass=${proxy_password}"
} else {
$proxycli = " --proxy=${proxy_scheme}://${proxy_hostname}:${proxy_port}"
" --proxy=${proxy_scheme}://${proxy_hostname}:${proxy_port}"
}
} else {
$proxycli = ''
''
}

package { 'subscription-manager':
Expand Down Expand Up @@ -190,8 +206,21 @@
ensure => present,
}

if $_user.is_a(Deferred) or $_password.is_a(Deferred) or $_org.is_a(Deferred) or $_activationkey.is_a(Deferred) {
$variables = {
'name' => $facts['networking']['fqdn'],
'user' => $_user,
'password' => $_password,
'org' => $_org,
'activationkey' => $_activationkey,
'proxycli' => $proxycli,
}
$_reg_command = Sensitive(Deferred('inline_epp', ['subscription-manager register --name="<%= $name %>"<%= $user %><%= $password %><%= $org %><%= $activationkey %><%= $proxycli %>', $variables]))
} else {
$_reg_command = Sensitive("subscription-manager register --name='${facts['networking']['fqdn']}'${_user}${_password}${_org}${_activationkey}${proxycli}")
}
exec { 'RHSM-register':
command => Sensitive("subscription-manager register --name='${facts['networking']['fqdn']}'${_user}${_password}${_org}${_activationkey}${proxycli}"),
command => $_reg_command,
creates => '/etc/pki/consumer/cert.pem',
path => '/bin:/usr/bin:/usr/sbin',
require => File['/etc/rhsm/rhsm.conf'],
Expand Down

0 comments on commit 51b08d4

Please sign in to comment.