Last active
August 29, 2015 14:27
-
-
Save flashvoid/d63ad92584ab09c26a88 to your computer and use it in GitHub Desktop.
userdata for calco-chef
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 -x | |
if ! ls /etc/apt/sources.list.d/ | grep project-calico-icehouse-trusty.list; then | |
dpkg --add-architecture i386 | |
apt-add-repository -y ppa:project-calico/icehouse | |
fi | |
apt-get update && apt-get install -y git docker.io | |
IP=`ec2metadata --local-ipv4` | |
if ! docker ps | grep chef-server; then | |
wget https://s3-us-west-1.amazonaws.com/pani-infrastructure/dist/chef-server.tar.gz -O /tmp/chef-server.tar.gz | |
docker load -i /tmp/chef-server.tar.gz | |
rm /tmp/chef-server.tar.gz | |
docker run --privileged -e CHEF_PORT=443 --name chef-server -d -p 443:443 cbuisson/chef-server | |
until nc -z localhost 443; do echo .; sleep 1; done | |
fi | |
if ! test -d /etc/chef; then | |
mkdir /etc/chef | |
fi | |
if ! test -f /tmp/knife_admin_key.tar.gz; then | |
( cd /tmp && until tar -tzf /tmp/knife_admin_key.tar.gz; do curl -Ok https://$IP/knife_admin_key.tar.gz; sleep 5; done ) | |
fi | |
if ! test -d /root/.chef; then | |
mkdir /root/.chef | |
fi | |
if ! test -f /etc/chef/admin.pem; then | |
tar -zxvf /tmp/knife_admin_key.tar.gz -C /etc/chef | |
fi | |
if ! test -h /etc/chef/validation.pem; then | |
ln -s /etc/chef/chef-validator.pem /etc/chef/validation.pem | |
fi | |
if ! test -f /etc/chef/node.json; then | |
cat >/etc/chef/node.json<<-EOF | |
{ | |
"fqdn" : "__IP__", | |
"run_list" : [ | |
"recipe[apt]", | |
"recipe[calico::control]" | |
] | |
} | |
EOF | |
sed -i "s/__IP__/$IP/g" /etc/chef/node.json | |
fi | |
if ! test -h /etc/chef-server; then | |
ln -s /etc/chef /etc/chef-server | |
fi | |
if ! test -f /etc/chef/client.rb; then | |
echo 'ssl_verify_mode :verify_none' >> /etc/chef/client.rb | |
fi | |
if ! test -f /root/.chef/admin.pem; then | |
cp /etc/chef/admin.pem /root/.chef/admin.pem | |
fi | |
if ! test -f /root/.chef/knife.rb; then | |
cat >/root/.chef/knife.rb<<-EOF | |
log_level :info | |
log_location STDOUT | |
node_name 'admin' | |
client_key '/root/.chef/admin.pem' | |
validation_client_name 'chef-validator' | |
validation_key '/etc/chef-server/chef-validator.pem' | |
chef_server_url 'https://__IP__' | |
syntax_check_cache_path '/root/.chef/syntax_check_cache' | |
cookbook_path [ '/var/chef/cookbooks' ] | |
ssl_verify_mode :verify_none | |
EOF | |
sed -i "s/__IP__/$IP/g" /root/.chef/knife.rb | |
fi | |
if ! test -d /var/chef; then | |
git clone https://github.com/projectcalico/calico-chef.git /var/chef | |
fi | |
if ! which knife; then | |
curl -L https://www.chef.io/chef/install.sh | sudo bash | |
fi | |
until knife cookbook show calico -c /root/.chef/knife.rb; do | |
(cd /var/chef/cookbooks && knife upload . -c /root/.chef/knife.rb); | |
sleep 5; | |
done | |
if ! test -d /etc/calico; then | |
mkdir /etc/calico | |
fi | |
if ! dpkg -l | grep calico-acl-manager; then | |
apt-get install -y calico-acl-manager | |
fi | |
chef-client -j /etc/chef/node.json | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment