Adding Chapter 1 : Packer will build for you
This commit is contained in:
11
packer/provisioning/alpine/ansible.sh
Normal file
11
packer/provisioning/alpine/ansible.sh
Normal file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -xe
|
||||
|
||||
installPython()
|
||||
{
|
||||
apk add --no-cache python3
|
||||
ln -sf python3 /usr/bin/python
|
||||
}
|
||||
|
||||
installPython
|
29
packer/provisioning/alpine/cleanup.sh
Normal file
29
packer/provisioning/alpine/cleanup.sh
Normal file
@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -xe
|
||||
|
||||
source /root/provisioning/common.sh
|
||||
|
||||
removePkg()
|
||||
{
|
||||
apk del --no-cache $1
|
||||
return $?
|
||||
}
|
||||
|
||||
cleanProv()
|
||||
{
|
||||
rm -rf /root/provisioning
|
||||
return $?
|
||||
}
|
||||
|
||||
for pkg in ${PKG_TO_REMOVE}
|
||||
do
|
||||
removePkg ${pkg}
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "Warning : removing package ${pkg} failed with code $?"
|
||||
fi
|
||||
done
|
||||
|
||||
cleanProv
|
||||
exit $?
|
53
packer/provisioning/alpine/configure-onecontext.sh
Normal file
53
packer/provisioning/alpine/configure-onecontext.sh
Normal file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -xeo pipefail
|
||||
|
||||
# Install one-context
|
||||
wget https://github.com/OpenNebula/addon-context-linux/releases/download/v5.8.0/one-context-5.8.0-r1.apk
|
||||
apk add --allow-untrusted --no-cache one-context-5.8.0-r1.apk
|
||||
|
||||
apk add --no-cache e2fsprogs-extra
|
||||
apk add --no-cache haveged
|
||||
|
||||
# Enable VM contextualization
|
||||
rc-update add one-context default
|
||||
rc-update add haveged boot
|
||||
|
||||
rc-status
|
||||
|
||||
# Add DNS hook in one-context
|
||||
mkdir -p /usr/local/share/one-context/scripts
|
||||
cat > /usr/local/share/one-context/scripts/dns-nebula <<'EOF'
|
||||
#!/bin/sh
|
||||
|
||||
. /usr/share/one-context/scripts/utils.sh
|
||||
|
||||
dns_servers="$(getval ETH0_DNS)"
|
||||
|
||||
echo > /etc/resolv.conf
|
||||
for nameserver_address in $dns_servers; do
|
||||
echo "nameserver $nameserver_address" >> /etc/resolv.conf
|
||||
done
|
||||
EOF
|
||||
chmod +x /usr/local/share/one-context/scripts/dns-nebula
|
||||
ln -s /usr/local/share/one-context/scripts/dns-nebula /etc/one-context.d/01-dns-nebula
|
||||
|
||||
# Reset network interfaces
|
||||
cat > /etc/network/interfaces <<EOF
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
# BEGIN generated by /usr/share/one-context/scripts/network
|
||||
# Do not modify this block, any modifications will be lost after reboot!
|
||||
auto eth0
|
||||
iface eth0 inet dhcp
|
||||
# END generated
|
||||
EOF
|
||||
|
||||
# Disable resolv.conf overwriting
|
||||
mkdir -p /etc/udhcpc
|
||||
echo 'RESOLV_CONF=NO' >> /etc/udhcpc/udhcpc.conf
|
||||
|
||||
# Clean up
|
||||
rm -rf /root/*.apk
|
||||
|
||||
sync
|
8
packer/provisioning/alpine/finalize.sh
Normal file
8
packer/provisioning/alpine/finalize.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
|
||||
# Zeroize
|
||||
dd if=/dev/zero of=/myZeroFile
|
||||
rm -rf /myZeroFile
|
||||
sync
|
77
packer/provisioning/alpine/setup-alpine.sh
Normal file
77
packer/provisioning/alpine/setup-alpine.sh
Normal file
@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -xeo pipefail
|
||||
|
||||
setup-ntp -c chrony
|
||||
setup-apkrepos http://dl-cdn.alpinelinux.org/alpine/v3.10/main/ http://dl-cdn.alpinelinux.org/alpine/v3.10/community/
|
||||
|
||||
apk add --no-cache wget
|
||||
apk add --no-cache expect #util-linux coreutils
|
||||
apk add --no-cache haveged
|
||||
apk add --no-cache ca-certificates
|
||||
|
||||
rc-update add haveged boot
|
||||
service haveged start
|
||||
|
||||
update-ca-certificates
|
||||
|
||||
export DISKOPTS="-L"
|
||||
expect <<EOF
|
||||
set timeout 300
|
||||
|
||||
spawn setup-alpine
|
||||
|
||||
expect "Select keyboard layout**"
|
||||
send "fr\r"
|
||||
|
||||
expect "Select variant**"
|
||||
send "fr-azerty\r"
|
||||
|
||||
expect "Enter system hostname**"
|
||||
send "${VM_NAME}\r"
|
||||
|
||||
expect "Which one do you want to initialize**"
|
||||
send "eth0\r"
|
||||
|
||||
expect "Ip address for eth0**"
|
||||
send "dhcp\r"
|
||||
|
||||
expect "Do you want to do any manual network configuration**"
|
||||
send "no\r"
|
||||
|
||||
expect "New password:"
|
||||
send "${ROOT_PASSWORD}\r"
|
||||
|
||||
expect "Retype password:"
|
||||
send "${ROOT_PASSWORD}\r"
|
||||
|
||||
expect "Which timezone are you in**"
|
||||
send "Europe/Paris\r"
|
||||
|
||||
expect "HTTP/FTP proxy URL**"
|
||||
send "none\r"
|
||||
|
||||
expect "Enter mirror number**"
|
||||
send "done\r"
|
||||
|
||||
expect "Which SSH server**"
|
||||
send "openssh\r"
|
||||
|
||||
expect "Which disk*s* would you like to use**"
|
||||
send "vda\r"
|
||||
|
||||
expect "How would you like to use it**"
|
||||
send "sys\r"
|
||||
|
||||
expect "WARNING: Erase the above disk*s* and continue**"
|
||||
send "y\r"
|
||||
|
||||
expect eof
|
||||
EOF
|
||||
|
||||
# Remove expect package
|
||||
apk del --no-cache expect
|
||||
|
||||
sync
|
||||
|
||||
reboot
|
@ -0,0 +1 @@
|
||||
06eab9a4d3ce28ce31d413b78b6ff94285e432179b6a6cba711e6c6653667567 alpine-virt-3.10.2-x86_64.iso
|
@ -0,0 +1 @@
|
||||
fe694a34c0e2d30b9e5dea7e2c1a3892c1f14cb474b69cc5c557a52970071da5 alpine-virt-3.12.0-x86_64.iso
|
54
packer/provisioning/alpine/syslog.sh
Normal file
54
packer/provisioning/alpine/syslog.sh
Normal file
@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -xe
|
||||
|
||||
source /root/provisioning/common.sh
|
||||
|
||||
installRsyslogRelp()
|
||||
{
|
||||
apk add --no-cache rsyslog-relp
|
||||
}
|
||||
|
||||
installNodeExporter()
|
||||
{
|
||||
local node_exporter_version="0.18.1"
|
||||
local node_exporter_archive="node_exporter-${node_exporter_version}.linux-amd64.tar.gz"
|
||||
local node_exporter_url="https://github.com/prometheus/node_exporter/releases/download/v${node_exporter_version}/${node_exporter_archive}"
|
||||
local node_exporter_sum="b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424"
|
||||
|
||||
cd /tmp
|
||||
downloadArchive ${node_exporter_url} ${node_exporter_sum} ${node_exporter_archive} sha256sum
|
||||
extractArchiveXZ ${node_exporter_archive} /srv/node_exporter
|
||||
cd -
|
||||
}
|
||||
|
||||
confSyslog()
|
||||
{
|
||||
SYSLOG_CONF_DIR="/etc/rsyslog.d/"
|
||||
SYSLOG_CONF_FILE="${SYSLOG_CONF_DIR}/aggregation.conf"
|
||||
QUEUE_DIR="/var/log/rsyslog/queues"
|
||||
|
||||
if [ ! -d ${SYSLOG_CONF_DIR} ]
|
||||
then
|
||||
mkdir ${SYSLOG_CONF_DIR}
|
||||
fi
|
||||
|
||||
if [ ! -d ${QUEUE_DIR} ]
|
||||
then
|
||||
mkdir -p ${QUEUE_DIR}
|
||||
fi
|
||||
|
||||
echo "\$WorkDirectory ${QUEUE_DIR}" >> ${SYSLOG_CONF_FILE}
|
||||
echo "\$ActionQueueType LinkedList" >> ${SYSLOG_CONF_FILE}
|
||||
echo "\$ActionQueueFileName send_all" >> ${SYSLOG_CONF_FILE}
|
||||
echo "\$ActionQueueSaveOnShutdown on" >> ${SYSLOG_CONF_FILE}
|
||||
echo "" >> ${SYSLOG_CONF_FILE}
|
||||
echo "*.* :omrelp:${SYSLOG_SERVER}:${SYSLOG_PORT}" >> ${SYSLOG_CONF_FILE}
|
||||
}
|
||||
|
||||
cat /etc/resolv.conf
|
||||
|
||||
#Not needed for ber
|
||||
#installRsyslogRelp
|
||||
#installNodeExporter
|
||||
#confSyslog
|
Reference in New Issue
Block a user