Created
December 25, 2014 19:10
-
-
Save pabluk/0e905208ad2b198037a2 to your computer and use it in GitHub Desktop.
Create a container LXC to test salt formulas on Debian
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
#!/bin/bash | |
PROJECT_DIR=$(pwd) | |
CNAME=$1 | |
CNAME_ROOTFS=/var/lib/lxc/$CNAME/rootfs | |
usage() { | |
echo "Usage: `basename $0` <container-name>" | |
echo "" | |
echo "Create a LXC container and setup salt in masterless mode." | |
echo "It assumes that your current work directory is a salt" | |
echo "formula project." | |
echo "" | |
echo "This script must be run as root." | |
echo "" | |
} | |
if [ -z $CNAME ]; then | |
usage | |
exit 1 | |
fi | |
if [[ $EUID -ne 0 ]]; then | |
usage | |
exit 1 | |
fi | |
lxc-create -n $CNAME -t debian -- -r wheezy | |
mkdir -p $CNAME_ROOTFS/srv/salt | |
mkdir -p $CNAME_ROOTFS/srv/pillar | |
mkdir -p $CNAME_ROOTFS/srv/formulas/$CNAME | |
echo "lxc.mount.entry=$PROJECT_DIR $CNAME_ROOTFS/srv/formulas/$CNAME none, defaults,bind,uid=0 0 0" >> /var/lib/lxc/$CNAME/config | |
lxc-start --daemon --name $CNAME | |
while true; do | |
IP=`sudo lxc-info --ips --name $CNAME` | |
if [ ! -z "$IP" ]; then | |
break | |
fi | |
sleep 1 | |
done | |
cat > $CNAME_ROOTFS/root/bootstrap.sh << EOF | |
#!/bin/sh | |
apt-get update | |
apt-get install --yes wget | |
wget -q -O- "http://debian.saltstack.com/debian-salt-team-joehealy.gpg.key" | apt-key add - | |
echo "deb http://debian.saltstack.com/debian wheezy-saltstack-2014-01 main" > /etc/apt/sources.list.d/saltstack.list | |
apt-get update | |
apt-get install --yes salt-minion | |
EOF | |
lxc-attach --name $CNAME -- sh /root/bootstrap.sh | |
cat > $CNAME_ROOTFS/etc/salt/minion.d/masterless.conf << EOF | |
file_client: local | |
file_roots: | |
base: | |
- /srv/salt | |
- /srv/formulas/$CNAME | |
EOF | |
cat > $CNAME_ROOTFS/srv/salt/top.sls << EOF | |
base: | |
'*': | |
- packages | |
EOF | |
cat > $CNAME_ROOTFS/srv/salt/packages.sls << EOF | |
install_base_packages: | |
pkg.installed: | |
- pkgs: | |
- vim | |
- less | |
EOF | |
echo "" | |
echo "You can connect to the new container typing:" | |
echo "" | |
echo "ssh root@$CNAME.lxc" | |
echo "" | |
echo "Root password is 'root'." | |
echo "Run a highstate with" | |
echo "" | |
echo "salt-call state.highstate" | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment