forked from waldirio/poc_sat6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsatpoc.sh
executable file
·196 lines (146 loc) · 4.65 KB
/
satpoc.sh
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
#######
# Vars
CLI_CONF_HAMMER="/root/cli_config.yml"
ORGANIZATION="ACME"
LOCATION="CITY"
ADMIN_USER="admin"
PASSWORD_ADMIN="redhat"
REPOS=""
CV="cv_rhel72_base"
CCV="ccv_rhel7_base_acme"
LIFECYCLE=""
MANIFEST=""
#######
####################
LOG="/var/log/satinstallation.log"
logline()
{
# Prints a message to stdout and to a log file
# The log file is defined by the $LOG global variable
echo "$1" | tee -a "$LOG"
}
start_time()
{
clear
logline "# Starting installation - $(date)"
}
attach_ent()
{
logline "# Attaching pool"
# Collect here the subs availabe to Satellite.
subscription-manager attach --pool=xxxxxxxxxxxxxxxxxxxxxxxxx | tee -a $LOG
}
repos()
{
logline "# Enabling repos"
# Repos for rhel7
subscription-manager repos --disable "*" | tee -a $LOG
subscription-manager repos --enable rhel-7-server-rpms --enable rhel-server-rhscl-7-rpms --enable rhel-7-server-satellite-6.1-rpms | tee -a $LOG
}
conf_base()
{
logline "# Basic Configurations"
logline "######################"
#echo "# Stopping Firewall" | tee -a $LOG
logline "# Setting Firewall Rules"
# Firewall
firewall-cmd --add-port="53/udp" --add-port="53/tcp" \
--add-port="67/udp" --add-port="68/udp" \
--add-port="69/udp" --add-port="80/tcp" \
--add-port="443/tcp" --add-port="5647/tcp" \
--add-port="8140/tcp" \
&& firewall-cmd --permanent --add-port="53/udp" --add-port="53/tcp" \
--add-port="67/udp" --add-port="68/udp" \
--add-port="69/udp" --add-port="80/tcp" \
--add-port="443/tcp" --add-port="5647/tcp" \
--add-port="8140/tcp"
#systemctl stop firewalld
#systemctl disable firewalld
logline "# Disabling Selinux"
# Selinux
setenforce 0
sed -i -e 's/=enforcing/=permissive/g' /etc/selinux/config
logline "# Configuring hosts"
# Hostname
IP=$(ip a|grep "inet "|grep -v 127|awk '{print $2}'|cut -d/ -f1)
HOSTNAME_FQDN=$(hostname)
HOSTNAME_ALIAS=$(hostname -s)
TestHosts=$(grep $HOSTNAME_FQDN /etc/hosts|wc -l)
if [ $TestHosts -eq 0 ]; then
echo "$IP $HOSTNAME_FQDN $HOSTNAME_ALIAS" >>/etc/hosts
fi
# Installing vim
yum install vim -y
}
update_system()
{
logline "# Updating the OS"
logline "######################"
yum update -y
}
katello_install()
{
logline "# Installing the Katello"
logline "######################"
yum install katello -y | tee -a $LOG
#katello-installer --foreman-admin-username $ADMIN_USER --foreman-admin-password $PASSWORD_ADMIN | tee -a $LOG
katello-installer --foreman-initial-organization $ORGANIZATION --foreman-initial-location $LOCATION --foreman-admin-username $ADMIN_USER --foreman-admin-password $PASSWORD_ADMIN | tee -a $LOG
}
hammer_auth()
{
cat << HAMMEREND > /root/cli_config.yml
:foreman:
:host: 'https://localhost/'
:username: '$ADMIN_USER'
:password: '$PASSWORD_ADMIN'
HAMMEREND
}
hammer_general()
{
hammerFull="hammer -c $CLI_CONF_HAMMER"
# Importing manifest
$hammerFull subscription upload --file /root/manifest.zip --organization $ORGANIZATION
# Enable the repos
# =====
$hammerFull repository-set enable --organization "$ORGANIZATION" \
--product "Red Hat Enterprise Linux Server" \
--name "Red Hat Enterprise Linux 7 Server (Kickstart)" \
--releasever "7.2" --basearch "x86_64"
$hammerFull repository-set enable --organization "$ORGANIZATION" \
--product "Red Hat Enterprise Linux Server" \
--name "Red Hat Enterprise Linux 7 Server (RPMs)" \
--releasever "7.2" --basearch "x86_64"
$hammerFull repository-set enable --organization "$ORGANIZATION" \
--product "Red Hat Enterprise Linux Server" \
--name "Red Hat Satellite Tools 6.1 (for RHEL 7 Server) (RPMs)" \
--basearch "x86_64"
# =====
# Start Sync
# =====
listIdStartSync=$(hammer -c /root/cli_config.yml repository list --organization ACME|awk '{print $1}'|grep -E '(^[0-9])')
listIdStartSync=$(hammer -c /root/cli_config.yml repository list --organization $ORGANIZATION|awk '{print $1}'|grep -E '(^[0-9])')
for b in $listIdStartSync
do
$hammerFull repository synchronize --id $b --organization $ORGANIZATION --async
done
# =====
# LifeCycle
$hammerFull lifecycle-environment create --label dev-rhel72 --name dev-rhel72 --organization $ORGANIZATION --prior Library
$hammerFull lifecycle-environment create --label qa-rhel72 --name qa-rhel72 --organization $ORGANIZATION --prior dev-rhel72
$hammerFull lifecycle-environment create --label prod-rhel72 --name prod-rhel72 --organization $ORGANIZATION --prior qa-rhel72
}
stop_time()
{
logline "# Finishing the installation - $(date)"
}
# Main
start_time
attach_ent
repos
conf_base
update_system
katello_install
hammer_auth
hammer_general
stop_time