-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
init.pp
139 lines (124 loc) · 3.85 KB
/
init.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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
# rhsm
#
# Subscribe the node to RHSM
#
# Copyright 2014 Ger Apeldoorn, unless otherwise noted.
#
# @summary Subscribe the node to RHSM
#
# @param rh_user [String] User for the Customer Portal.
# You need to specify either (rh_user and rh_password) or (org and activationkey)
# @param rh_password [String] Password for the rh_user account
# @param org [String] Organization to use
# @param activationkey [String] Activationkey to use
# @param servername [String] Servername, default provided
# Used directly in rhsm.conf template
# @param pool [String] Attach system to a specific pool instead of auto attach to compatible subscriptions
# @param proxy_hostname [String] Proxy hostname
# @param proxy_port [String] Proxy port
# @param proxy_user [String] Proxy user
# @param proxy_password [String] Proxy password
# @param baseurl [String] Base URL for rhsm, default provided
# @param package_ensure [String] Whether to install subscription-manager
# @param repo_extras [Boolean] Enable extras repository
# @param repo_optional [Boolean] Enable optional repository
#
# @example
# include rhsm
#
# @example
# # Hierafile:
# ---
# rhsm::rh_user: myuser
# rhsm::rh_password: mypassword
#
# @author Ger Apeldoorn <info@gerapeldoorn.nl>
#
class rhsm (
$rh_user = undef,
$rh_password = undef,
$org = undef,
$activationkey = undef,
$servername = 'subscription.rhsm.redhat.com',
$pool = undef,
$proxy_hostname = undef,
$proxy_port = undef,
$proxy_user = undef,
$proxy_password = undef,
$baseurl = 'https://cdn.redhat.com',
$package_ensure = 'latest',
$repo_extras = false,
$repo_optional = false
) {
if ($rh_user == undef and $rh_password == undef) and ($org == undef and $activationkey == undef) {
fail("${module_name}: Must provide rh_user and rh_password or org and activationkey")
}
if $rh_user {
$_user = " --username='${rh_user}'"
} else {
$_user = ''
}
if $rh_password {
$_password = " --password='${rh_password}'"
} else {
$_password = ''
}
if $org {
$_org = " --org='${org}'"
} else {
$_org = ''
}
if $activationkey {
$_activationkey = " --activationkey='${activationkey}'"
} else {
$_activationkey = ''
}
if $proxy_hostname {
if $proxy_user and $proxy_password {
$proxycli = " --proxy=http://${proxy_hostname}:${proxy_port} --proxyuser=${proxy_user} --proxypass=${proxy_password}"
} else {
$proxycli = " --proxy=http://${proxy_hostname}:${proxy_port}"
}
} else {
$proxycli = ''
}
if $pool == undef {
$command = "subscription-manager attach --auto${proxycli}"
} else {
$command = "subscription-manager attach --pool=${pool}${proxycli}"
}
package { 'subscription-manager':
ensure => $package_ensure,
}
exec {'sm yum clean all':
command => '/usr/bin/yum clean all',
refreshonly => true,
subscribe => Package['subscription-manager'],
}
file { '/etc/rhsm/rhsm.conf':
ensure => file,
content => template('rhsm/rhsm.conf.erb'),
}
exec { 'RHSM-register':
command => "subscription-manager register --name='${::fqdn}'${_user}${_password}${_org}${_activationkey}${proxycli}",
onlyif => 'subscription-manager identity 2>&1 | grep "not yet registered"',
path => '/bin:/usr/bin:/usr/sbin',
require => Package['subscription-manager'],
}
exec { 'RHSM-subscribe':
command => $command,
onlyif => 'subscription-manager list 2>&1 | grep "Expired\|Not Subscribed\|Unknown"',
path => '/bin:/usr/bin:/usr/sbin',
require => Exec['RHSM-register'],
}
if $repo_extras {
::rhsm::repo { "rhel-${::operatingsystemmajrelease}-server-extras-rpms":
require => Exec['RHSM-register'],
}
}
if $repo_optional {
::rhsm::repo { "rhel-${::operatingsystemmajrelease}-server-optional-rpms":
require => Exec['RHSM-register'],
}
}
}