Convert salt to ansible
This commit is contained in:
parent
3f9cd642e0
commit
6756cfa6b5
4 changed files with 34 additions and 69 deletions
|
@ -1,5 +0,0 @@
|
||||||
state_verbose: False
|
|
||||||
file_client: local
|
|
||||||
file_roots:
|
|
||||||
base:
|
|
||||||
- /srv/salt
|
|
|
@ -22,10 +22,8 @@ readonly INSTALLATION_ESP_PARTITION_SIZE=4
|
||||||
readonly INSTALLATION_MOUNTPOINT='/mnt'
|
readonly INSTALLATION_MOUNTPOINT='/mnt'
|
||||||
readonly INSTALLATION_NOVERIA_BIN='/usr/local/noveria/bin'
|
readonly INSTALLATION_NOVERIA_BIN='/usr/local/noveria/bin'
|
||||||
readonly INSTALLATION_SECRETS_FILE="/root/installation.secrets"
|
readonly INSTALLATION_SECRETS_FILE="/root/installation.secrets"
|
||||||
readonly INSTALLATION_SALT_ROOT="srv/salt"
|
readonly INSTALLATION_ANSIBLE_ROOT="srv/ansible"
|
||||||
readonly INSTALLATION_SALT_GIT="https://git.noveria.org/Novos/salt-statetree.git"
|
readonly INSTALLATION_ANSIBLE_GIT="https://git.noveria.org/Novos/ansible-playbooks.git"
|
||||||
readonly INSTALLATION_PILLAR_ROOT="srv/pillar"
|
|
||||||
readonly INSTALLATION_PILLAR_GIT="https://git.noveria.org/Novos/salt-pillartree.git"
|
|
||||||
readonly INSTALLATION_ALPINE_VERSION=$(cat /etc/os-release | grep VERSION_ID | cut -d= -f2)
|
readonly INSTALLATION_ALPINE_VERSION=$(cat /etc/os-release | grep VERSION_ID | cut -d= -f2)
|
||||||
|
|
||||||
# Colors
|
# Colors
|
||||||
|
@ -148,8 +146,8 @@ function preChecks() {
|
||||||
function introDialogue() {
|
function introDialogue() {
|
||||||
local introtext="\n\n\n
|
local introtext="\n\n\n
|
||||||
Velkommen til
|
Velkommen til
|
||||||
_ _ _
|
_ _ _
|
||||||
| \ | | _____ _____ _ __(_) __ _
|
| \ | | _____ _____ _ __(_) __ _
|
||||||
| \| |/ _ \ \ / / _ \ '__| |/ _ |
|
| \| |/ _ \ \ / / _ \ '__| |/ _ |
|
||||||
| |\ | (_) \ V / __/ | | | (_| |
|
| |\ | (_) \ V / __/ | | | (_| |
|
||||||
|_| \_|\___/ \_/ \___|_| |_|\__,_|
|
|_| \_|\___/ \_/ \___|_| |_|\__,_|
|
||||||
|
@ -157,7 +155,7 @@ function introDialogue() {
|
||||||
OS: Novos
|
OS: Novos
|
||||||
Version: $(date "+%Y%m")
|
Version: $(date "+%Y%m")
|
||||||
IP: $(ifconfig eth0 | grep "inet addr" | awk '{$1=$1};1' | awk '{print $2}' | cut -d: -f2)
|
IP: $(ifconfig eth0 | grep "inet addr" | awk '{$1=$1};1' | awk '{print $2}' | cut -d: -f2)
|
||||||
|
|
||||||
How do you want to continue?
|
How do you want to continue?
|
||||||
"
|
"
|
||||||
dialog --stdout --clear --cr-wrap --no-collapse --yes-label "Graphical Guide" --no-label "Alpine shell" --yesno "$introtext" 31 93
|
dialog --stdout --clear --cr-wrap --no-collapse --yes-label "Graphical Guide" --no-label "Alpine shell" --yesno "$introtext" 31 93
|
||||||
|
@ -259,7 +257,7 @@ Disk: $INSTALLATION_DISK
|
||||||
function installation() {
|
function installation() {
|
||||||
# clear display
|
# clear display
|
||||||
clear
|
clear
|
||||||
|
|
||||||
# lock file
|
# lock file
|
||||||
touch "$INSTALLATION_LOCK_FILE" || installationFailed
|
touch "$INSTALLATION_LOCK_FILE" || installationFailed
|
||||||
|
|
||||||
|
@ -323,7 +321,7 @@ function installation() {
|
||||||
|
|
||||||
installationSubtaskTitle "Mount ESP"
|
installationSubtaskTitle "Mount ESP"
|
||||||
mount -o nodev,nosuid,noexec "${ESP_PARTITION}" "${INSTALLATION_MOUNTPOINT}/efi" || installationFailed
|
mount -o nodev,nosuid,noexec "${ESP_PARTITION}" "${INSTALLATION_MOUNTPOINT}/efi" || installationFailed
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "┌──────────────────────────────────────────┐"
|
echo "┌──────────────────────────────────────────┐"
|
||||||
echo "│ Install and configure OS │"
|
echo "│ Install and configure OS │"
|
||||||
|
@ -342,7 +340,7 @@ function installation() {
|
||||||
|
|
||||||
installationSubtaskTitle "Setup PATH"
|
installationSubtaskTitle "Setup PATH"
|
||||||
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'" || installationFailed
|
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'" || installationFailed
|
||||||
|
|
||||||
installationSubtaskTitle "Mount extra mounts for chroot"
|
installationSubtaskTitle "Mount extra mounts for chroot"
|
||||||
mount -t proc /proc "${INSTALLATION_MOUNTPOINT}/proc" || installationFailed
|
mount -t proc /proc "${INSTALLATION_MOUNTPOINT}/proc" || installationFailed
|
||||||
mount -t sysfs /sys "${INSTALLATION_MOUNTPOINT}/sys" || installationFailed
|
mount -t sysfs /sys "${INSTALLATION_MOUNTPOINT}/sys" || installationFailed
|
||||||
|
@ -353,16 +351,16 @@ function installation() {
|
||||||
|
|
||||||
installationSubtaskTitle "Install base-packages"
|
installationSubtaskTitle "Install base-packages"
|
||||||
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "apk add alpine-base --no-cache" || installationFailed
|
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "apk add alpine-base --no-cache" || installationFailed
|
||||||
|
|
||||||
installationSubtaskTitle "Overwrite default repositories"
|
installationSubtaskTitle "Overwrite default repositories"
|
||||||
cp /etc/apk/repositories "${INSTALLATION_MOUNTPOINT}/etc/apk/repositories" || installationFailed
|
cp /etc/apk/repositories "${INSTALLATION_MOUNTPOINT}/etc/apk/repositories" || installationFailed
|
||||||
|
|
||||||
installationSubtaskTitle "Install SaltStack"
|
installationSubtaskTitle "Install Ansible"
|
||||||
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "apk add salt-minion envsubst" || installationFailed
|
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "apk add ansible envsubst" || installationFailed
|
||||||
|
|
||||||
installationSubtaskTitle "Setup keymap"
|
installationSubtaskTitle "Setup keymap"
|
||||||
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "setup-keymap ch ch" || installationFailed
|
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "setup-keymap ch ch" || installationFailed
|
||||||
|
|
||||||
installationSubtaskTitle "Setting localtime to Europe/Zurich"
|
installationSubtaskTitle "Setting localtime to Europe/Zurich"
|
||||||
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "setup-timezone Europe/Zurich" || installationFailed
|
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "setup-timezone Europe/Zurich" || installationFailed
|
||||||
|
|
||||||
|
@ -386,65 +384,37 @@ function installation() {
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "┌──────────────────────────────────────────┐"
|
echo "┌──────────────────────────────────────────┐"
|
||||||
echo "│ Configure SaltStack and highstate │"
|
echo "│ Configure Ansible and playbook-run │"
|
||||||
echo "└──────────────────────────────────────────┘"
|
echo "└──────────────────────────────────────────┘"
|
||||||
|
|
||||||
installationSubtaskTitle "Clone Salt-Repo"
|
installationSubtaskTitle "Clone Playbook-repo"
|
||||||
mkdir -p ${INSTALLATION_MOUNTPOINT}/${INSTALLATION_SALT_ROOT}
|
mkdir -p ${INSTALLATION_MOUNTPOINT}/${INSTALLATION_ANSIBLE_ROOT}/playbooks
|
||||||
git clone ${INSTALLATION_SALT_GIT} ${INSTALLATION_MOUNTPOINT}/${INSTALLATION_SALT_ROOT}
|
git clone ${INSTALLATION_ANSIBLE_GIT} ${INSTALLATION_MOUNTPOINT}/${INSTALLATION_ANSIBLE_ROOT}/playbooks
|
||||||
|
|
||||||
cat >"${INSTALLATION_MOUNTPOINT}/etc/salt/minion" <<EOT || installationFailed
|
mkdir -p ${INSTALLATION_MOUNTPOINT}/etc/ansible
|
||||||
---
|
cat >"${INSTALLATION_MOUNTPOINT}/etc/ansible/ansible.cfg" <<EOT || installationFailed
|
||||||
state_verbose: False
|
[defaults]
|
||||||
file_client: local
|
inventory=/${INSTALLATION_ANSIBLE_ROOT}/inventory.yml
|
||||||
file_roots:
|
|
||||||
base:
|
|
||||||
- /srv/salt
|
|
||||||
pillar_roots:
|
|
||||||
base:
|
|
||||||
- /srv/pillar
|
|
||||||
...
|
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
cat >"${INSTALLATION_MOUNTPOINT}/etc/salt/grains" <<EOT || installationFailed
|
cat >"${INSTALLATION_MOUNTPOINT}/${INSTALLATION_ANSIBLE_ROOT}/inventory.yml" <<EOT
|
||||||
os: Alpine
|
ungrouped:
|
||||||
os_family: Alpine
|
hosts:
|
||||||
|
localhost
|
||||||
|
vars:
|
||||||
|
ansible_connection: local
|
||||||
|
start_timestamp: ${START_TIMESTAMP}
|
||||||
|
tmpfs_size: 4G
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
cat >"${INSTALLATION_MOUNTPOINT}/${INSTALLATION_SALT_ROOT}/serverspecific.sls" <<SERVERSPECIFIC || installationFailed
|
installationSubtaskTitle "Execute Ansible playbooks"
|
||||||
include:
|
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "ansible-playbook /${INSTALLATION_ANSIBLE_ROOT}/playbooks/top.ansible.yml" || installationFailed
|
||||||
SERVERSPECIFIC
|
|
||||||
|
|
||||||
for additional in ${ADDITIONAL_STATES_ARR[@]}; do
|
|
||||||
echo -e " - $additional" >> "${INSTALLATION_MOUNTPOINT}/${INSTALLATION_SALT_ROOT}/serverspecific.sls"
|
|
||||||
done
|
|
||||||
|
|
||||||
installationSubtaskTitle "Populate Pillars"
|
|
||||||
mkdir -p ${INSTALLATION_MOUNTPOINT}/${INSTALLATION_PILLAR_ROOT}
|
|
||||||
#git clone ${INSTALLATION_PILLAR_GIT} ${INSTALLATION_MOUNTPOINT}/${INSTALLATION_PILLAR_ROOT}
|
|
||||||
cat >"${INSTALLATION_MOUNTPOINT}/${INSTALLATION_PILLAR_ROOT}/top.sls" << EOT
|
|
||||||
base:
|
|
||||||
'*':
|
|
||||||
EOT
|
|
||||||
for state in $(find ${INSTALLATION_MOUNTPOINT}/${INSTALLATION_SALT_ROOT} -mindepth 1 -maxdepth 1 -not -path '*/.*' -type d -exec basename {} \;); do
|
|
||||||
mkdir -p ${INSTALLATION_MOUNTPOINT}/${INSTALLATION_PILLAR_ROOT}/${state}
|
|
||||||
touch ${INSTALLATION_MOUNTPOINT}/${INSTALLATION_PILLAR_ROOT}/${state}/init.sls
|
|
||||||
echo -e " - $state" >> ${INSTALLATION_MOUNTPOINT}/${INSTALLATION_PILLAR_ROOT}/top.sls
|
|
||||||
done
|
|
||||||
|
|
||||||
cat >"${INSTALLATION_MOUNTPOINT}/${INSTALLATION_PILLAR_ROOT}/system/init.sls" << EOT
|
|
||||||
system.disks.timestamp: ${START_TIMESTAMP}
|
|
||||||
system.disks.tmpfs.size: 4G
|
|
||||||
EOT
|
|
||||||
|
|
||||||
installationSubtaskTitle "Salt highstate"
|
|
||||||
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "salt-call state.highstate" || installationFailed
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "┌──────────────────────────────────────────┐"
|
echo "┌──────────────────────────────────────────┐"
|
||||||
echo "│ Boot │"
|
echo "│ Boot │"
|
||||||
echo "└──────────────────────────────────────────┘"
|
echo "└──────────────────────────────────────────┘"
|
||||||
|
|
||||||
installationSubtaskTitle "Make EFI boot image with mkinitfs"
|
installationSubtaskTitle "Make EFI boot image with mkinitfs"
|
||||||
latest_kernel="$(chroot $INSTALLATION_MOUNTPOINT /bin/ash -c 'echo $(apk search linux-lts | head -n1 | cut -d- -f3- | sed "s|r||")-lts')"
|
latest_kernel="$(chroot $INSTALLATION_MOUNTPOINT /bin/ash -c 'echo $(apk search linux-lts | head -n1 | cut -d- -f3- | sed "s|r||")-lts')"
|
||||||
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "mkinitfs $latest_kernel" || installationFailed
|
chroot "${INSTALLATION_MOUNTPOINT}" /bin/ash -c "mkinitfs $latest_kernel" || installationFailed
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
linux-lts
|
linux-lts
|
||||||
linux-firmware-none
|
linux-firmware-none
|
||||||
salt-minion
|
ansible
|
||||||
zsh
|
zsh
|
||||||
vim
|
vim
|
||||||
btrfs-progs
|
btrfs-progs
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
|
|
||||||
iso_name="novos"
|
iso_name="novos-ansible"
|
||||||
iso_label="NOVOS_$(date --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%Y%m%d)"
|
iso_label="NOVOS_$(date --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%Y%m%d)-ANSIBLE"
|
||||||
iso_publisher="Noveria Network <https://noveria.org>"
|
iso_publisher="Noveria Network <https://noveria.org>"
|
||||||
iso_application="Alpine-Linux Based Server OS for Noveria"
|
iso_application="Alpine-Linux Based Server OS for Noveria"
|
||||||
iso_version="v3.20"
|
iso_version="v3.20"
|
||||||
|
|
Loading…
Reference in a new issue