Last active
July 17, 2020 07:53
-
-
Save hbokh/4ca0838e9b8154a29c13bff7a7c7dba2 to your computer and use it in GitHub Desktop.
Script to deploy Cobbler 3 and test terrafrom-provider-cobbler in Fedora 31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# When enabled this will fetch lots of updates! | |
#sudo dnf update -y | |
sudo dnf install -y make automake gcc gcc-c++ git wget | |
cd | |
echo "export PATH=$PATH:$HOME/terraform:$HOME/go/bin" >> ~/.bashrc | |
export PATH=$PATH:$HOME/terraform:$HOME/go/bin | |
if [ ! -d "/root/go" ]; then | |
# Give me Golang 1.14 | |
sudo wget -O /usr/local/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | |
sudo chmod +x /usr/local/bin/gimme | |
/usr/local/bin/gimme 1.14 >> ~/.bashrc | |
eval "$(/usr/local/bin/gimme 1.14)" | |
mkdir ~/go | |
echo "export GO111MODULE=on" >> ~/.bashrc | |
echo "export GOPATH=$HOME/go" >> ~/.bashrc | |
fi | |
export GOPATH=$HOME/go | |
source ~/.bashrc | |
if [ ! -d "/root/wearespindle/" ]; then | |
mkdir /root/wearespindle | |
cd /root/wearespindle | |
git clone https://github.com/wearespindle/terraform-provider-cobbler | |
git clone https://github.com/wearespindle/cobblerclient | |
fi | |
# Cobbler 3 - lots of changes and lots of bugs. | |
sudo dnf install -y cobbler cobbler-web debmirror dnsmasq fence-agents pykickstart xinetd | |
sudo tee /etc/cobbler/modules.conf <<EOF | |
[authentication] | |
module = authentication.configfile | |
[authorization] | |
module = authorization.allowall | |
[dns] | |
module = managers.dnsmasq | |
[dhcp] | |
module = managers.dnsmasq | |
[tftpd] | |
module = managers.in_tftpd | |
EOF | |
sudo tee /etc/cobbler/dnsmasq.template <<EOF | |
dhcp-range = 192.168.33.200,192.168.33.250 | |
server = 8.8.8.8 | |
read-ethers | |
addn-hosts = /var/lib/cobbler/cobbler_hosts | |
dhcp-option=3,\$next_server | |
dhcp-lease-max=1000 | |
dhcp-authoritative | |
dhcp-boot=pxelinux.0 | |
dhcp-boot=net:normalarch,pxelinux.0 | |
\$insert_cobbler_system_definitions | |
EOF | |
sudo sed -i -e 's/^manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings | |
sudo sed -i -e 's/^manage_dns: 0/manage_dns: 1/' /etc/cobbler/settings | |
sudo sed -i -e 's/^next_server:.*/next_server: 192.168.33.11/' /etc/cobbler/settings | |
sudo sed -i -e 's/^server:.*/server: 192.168.33.11/' /etc/cobbler/settings | |
sudo tee /etc/xinetd.d/tftp <<EOF | |
# default: off | |
# description: The tftp server serves files using the trivial file transfer \ | |
# protocol. The tftp protocol is often used to boot diskless \ | |
# workstations, download configuration files to network-aware printers, \ | |
# and to start the installation process for some operating systems. | |
service tftp | |
{ | |
disable = no | |
socket_type = dgram | |
protocol = udp | |
wait = yes | |
user = root | |
server = /usr/sbin/in.tftpd | |
server_args = -B 1380 -v -s /var/lib/tftpboot | |
per_source = 11 | |
cps = 100 2 | |
flags = IPv4 | |
} | |
EOF | |
# User: cobbler / Pass: cobbler | |
sudo tee /etc/cobbler/users.digest <<EOF | |
cobbler:Cobbler:a2d6bae81669d707b72c0bd9806e01f3 | |
EOF | |
# Start bugfixes ################################ | |
# Bugs not (yet) fixed upstream | |
# Create autoinstall symlinks. | |
if [ ! -L "/var/lib/cobbler/autoinstall_templates" ]; then | |
cd /var/lib/cobbler/ | |
sudo ln -s templates autoinstall_templates | |
sudo ln -s scripts autoinstall_scripts | |
sudo ln -s snippets autoinstall_snippets | |
fi | |
# Move the location block up, before WSGI. | |
sudo tee /etc/httpd/conf.d/cobbler_web.conf <<EOF | |
# This configuration file enables the cobbler web | |
# interface (django version) | |
Alias /cobbler_webui_content /var/www/cobbler_webui_content | |
<Location /cobbler_web> | |
Require all granted | |
</Location> | |
# Use separate process group for wsgi | |
WSGISocketPrefix /var/run/wsgi | |
WSGIScriptAlias /cobbler_web /usr/share/cobbler/web/cobbler.wsgi | |
WSGIDaemonProcess cobbler_web display-name=%{GROUP} | |
WSGIProcessGroup cobbler_web | |
WSGIPassAuthorization On | |
<VirtualHost *:80> | |
<Directory "/usr/share/cobbler/web/"> | |
<IfModule mod_ssl.c> | |
SSLRequireSSL | |
</IfModule> | |
<IfModule mod_nss.c> | |
NSSRequireSSL | |
</IfModule> | |
SetEnv VIRTUALENV | |
Options Indexes MultiViews | |
AllowOverride None | |
Require all granted | |
</Directory> | |
<Directory "/var/www/cobbler_webui_content/"> | |
<IfModule mod_ssl.c> | |
SSLRequireSSL | |
</IfModule> | |
<IfModule mod_nss.c> | |
NSSRequireSSL | |
</IfModule> | |
Options +Indexes +FollowSymLinks | |
AllowOverride None | |
Require all granted | |
</Directory> | |
</VirtualHost> | |
EOF | |
# Show a Django error page and not Apache's "internal server error". | |
sudo tee /tmp/settings.py.diff <<EOF | |
--- settings.orig 2020-02-26 15:17:42.214432663 +0000 | |
+++ settings.py 2020-02-26 15:18:16.482245979 +0000 | |
@@ -19,8 +19,9 @@ | |
DATABASE_HOST = '' | |
DATABASE_PORT = '' | |
-# Force Django to use the systems timezone | |
-TIME_ZONE = None | |
+# Force Django to use a specific timezone | |
+TIME_ZONE = 'UTC' | |
+USE_TZ = True | |
# Language section | |
# TBD. | |
EOF | |
cd /usr/share/cobbler/web/ | |
sudo patch -N -p0 < /tmp/settings.py.diff || true | |
# Patch to disable aggressive caching added in Cobbler 3.x | |
# Will give this error if not patched: | |
# Fault(1): <class 'AttributeError'>:'str' object has no attribute 'copy' | |
# Leaving "(self, sorted=True)"" will give this error: | |
# Fault(1): <class 'TypeError'>:'<' not supported between instances of 'str' and 'NoneType' | |
# Both needed for the terraform-provider-cobbler!! | |
sudo tee /tmp/item.py.diff <<EOF | |
--- item.orig 2020-02-26 14:35:24.766136242 +0000 | |
+++ item.py 2020-02-26 12:25:55.187133099 +0000 | |
@@ -215,7 +215,7 @@ | |
utils.from_dict_from_fields(self, _dict, self.get_fields()) | |
def to_dict(self): | |
- # return utils.to_dict_from_fields(self, self.get_fields()) | |
+ return utils.to_dict_from_fields(self, self.get_fields()) | |
value = self.get_from_cache(self) | |
if value is None: | |
@@ -232,7 +232,7 @@ | |
def set_uid(self, uid): | |
self.uid = uid | |
- def get_children(self, sorted=True): | |
+ def get_children(self, sorted=False): | |
""" | |
Get direct children of this object. | |
""" | |
EOF | |
cd /usr/lib/python3.7/site-packages/cobbler/items/ | |
sudo patch -N -p0 < /tmp/item.py.diff || true | |
# Fix create & delete snippets with XMLRPC | |
sudo wget -q https://raw.githubusercontent.com/cobbler/cobbler/master/cobbler/autoinstall_manager.py -O /usr/lib/python3.7/site-packages/cobbler/autoinstall_manager.py | |
# Add fence_ipmitool wrapper script calling fence_impilan with lanplus enabled | |
sudo wget -q https://raw.githubusercontent.com/cobbler/cobbler/master/bin/fence_ipmitool -O /usr/sbin/fence_ipmitool | |
sudo chmod 755 /usr/sbin/fence_ipmitool | |
# END bugfixes ################################## | |
sudo systemctl daemon-reload | |
sudo systemctl enable cobblerd xinetd tftp | |
sudo systemctl restart httpd cobblerd xinetd tftp | |
sleep 3 | |
# Instead of downlaoding a ~900MB ISO, add the basic repo and distro for Ubuntu 18.04 | |
if [ ! -d "/var/www/cobbler/distro_mirror/Ubuntu-18.04" ]; then | |
UBUNTU_REPOSITORY="http://nl.archive.ubuntu.com/ubuntu/" | |
# Add Debian repository, not mirrored nor updated. | |
sudo cobbler repo add --name=Ubuntu-18.04-x86_64 \ | |
--apt-components='main' \ | |
--apt-dists='bionic' \ | |
--arch=x86_64 \ | |
--breed=apt \ | |
--keep-updated=no \ | |
--mirror=${UBUNTU_REPOSITORY} \ | |
--mirror-locally=no | |
# Copy kernel and initrd which will be used as installers. | |
sudo mkdir -p /var/www/cobbler/distro_mirror/Ubuntu-18.04/install/netboot/ubuntu-installer/amd64 | |
sudo rsync -av rsync://nl.archive.ubuntu.com:/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/ /var/www/cobbler/distro_mirror/Ubuntu-18.04/install/netboot/ubuntu-installer/amd64/ | |
# Create Cobbler distro and Cobbler profile. | |
sudo cobbler distro add --name=Ubuntu-18.04-x86_64 \ | |
--kernel=/var/www/cobbler/distro_mirror/Ubuntu-18.04/install/netboot/ubuntu-installer/amd64/linux \ | |
--initrd=/var/www/cobbler/distro_mirror/Ubuntu-18.04/install/netboot/ubuntu-installer/amd64/initrd.gz \ | |
--autoinstall-meta=tree=http://@@http_server@@/cblr/distro_mirror/Ubuntu-18.04-x86_64 \ | |
--arch=x86_64 \ | |
--breed=ubuntu \ | |
--os-version=bionic \ | |
--boot-loader=grub | |
fi | |
sudo cobbler get-loaders | |
sudo cobbler signature update | |
sudo cobbler sync | |
# Create a file with the cobbler credential environment variables | |
cat > ~/cobblerc <<EOF | |
export COBBLER_USERNAME="cobbler" | |
export COBBLER_PASSWORD="cobbler" | |
export COBBLER_URL="http://localhost:25151" | |
EOF | |
echo " | |
Done! Open http://cobbler.internal/cobbler_web/ for | |
the Cobbler webUI and login with cobbler / cobbler. | |
" | |
echo " | |
When running a make testacc on the local machine, export these: | |
export COBBLER_USERNAME=cobbler | |
export COBBLER_PASSWORD=cobbler | |
export COBBLER_URL=http://cobbler.internal/cobbler_api | |
" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure("2") do |config| | |
config.vm.provider :virtualbox do |vb| | |
vb.customize ["modifyvm", :id, "--nictype1", "virtio" ] | |
vb.customize ["modifyvm", :id, "--nictype2", "virtio" ] | |
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] | |
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] | |
end | |
# Plugin vagrant-hostsupdater needs to be installed | |
config.vm.box = "bento/fedora-31" | |
config.vm.network "private_network", ip: "192.168.33.11" | |
config.vm.hostname = 'cobbler.internal' | |
config.vm.synced_folder '.', '/vagrant', type: 'nfs' | |
config.vm.provider "virtualbox" do |vb| | |
vb.memory = "2048" | |
end | |
# PROVISIONING | |
# Download the deploy.sh from https://gist.github.com/hbokh/4ca0838e9b8154a29c13bff7a7c7dba2 | |
config.vm.provision "shell", path: "deploy.sh" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment