Sie können die Distro auf dem Remote-Host erkennen und entsprechend bereitstellen. in deploy.sh:
DISTRO=`ssh -o 'StrictHostKeyChecking no' ${host} 'bash -s' < bootstrap.sh`
Die DISTRO Variable wird durch was auch immer von der bootstrap.sh Skript ausgegeben wird, die auf dem Hostcomputer ausgeführt wird. So können wir nun bootstrap.sh verwenden, um die Distro oder andere Servereinstellungen, die wir benötigen, und echo zu erkennen, die in das lokale Skript gesprudelt werden und Sie entsprechend reagieren können.
Beispiel deploy.sh:
#!/bin/bash
# Usage: ./deploy.sh [host]
host="${1}"
if [ -z "$host" ]; then
echo "Please provide a host - eg: ./deploy [email protected]"
exit 1
fi
echo "deploying to ${host}"
# The host key might change when we instantiate a new VM, so
# we remove (-R) the old host key from known_hosts
ssh-keygen -R "${host#*@}" 2> /dev/null
# rough test for what distro the server is on
DISTRO=`ssh -o 'StrictHostKeyChecking no' ${host} 'bash -s' < bootstrap.sh`
if [ "$DISTRO" == "FED" ]; then
echo "Detected a Fedora, RHEL, CentOS distro on host"
tar cjh . | ssh -o 'StrictHostKeyChecking no' "$host" '
rm -rf /tmp/chef &&
mkdir /tmp/chef &&
cd /tmp/chef &&
tar xj &&
bash install.sh'
elif [ "$DISTRO" == "DEB" ]; then
echo "Detected a Debian, Ubuntu distro on host"
tar cj . | ssh -o 'StrictHostKeyChecking no' "$host" '
sudo rm -rf ~/chef &&
mkdir ~/chef &&
cd ~/chef &&
tar xj &&
sudo bash install.sh'
fi
Beispiel bootstrap.sh:
#!/bin/bash
# Fedora/RHEL/CentOS distro
if [ -f /etc/redhat-release ]; then
echo "FED"
# Debian/Ubuntu
elif [ -r /lib/lsb/init-functions ]; then
echo "DEB"
fi
Dies ermöglicht es Ihnen, die Plattform sehr früh im Verteilungsprozess zu erkennen.
Haben Sie eine Frage? – Cairnarvon
Ich habe eine Lösung, die ich für andere nützlich finden könnte. Ich dachte, ich würde die Frage posten und dann beantworten - aber ich muss 8 Stunden warten. – offwhite