Instantly share code, notes, and snippets.

Embed
What would you like to do?
rancher bootstrap script
#cloud-config
write_files:
- path: "/etc/rancher-agent"
permissions: "0700"
owner: "root"
content: |
#!/bin/bash
# This script bootstraps the rancher agent for the new server on boot
INTERNAL_IP=$(ip add show eth0 | awk '/inet/ {print $2}' | cut -d/ -f1 | head -1)
SERVER="https://example.com"
TOKEN="access_key:secret_key"
PROJID="unique_id"
AGENT_VER="v1.0.1"
RANCHER_URL=$(curl -su $TOKEN $SERVER/v1/registrationtokens?projectId=$PROJID | head -1 | grep -nhoe 'registrationUrl[^},]*}' | egrep -hoe 'https?:.*[^"}]')
docker run \
-e CATTLE_AGENT_IP=$INTERNAL_IP \
-e CATTLE_HOST_LABELS='internal=true' \
-d --privileged --name rancher-bootstrap \
-v /var/run/docker.sock:/var/run/docker.sock \
rancher/agent:$AGENT_VER $RANCHER_URL
coreos:
units:
- name: rancher-agent.service
command: start
content: |
[Unit]
Description=Rancher Agent
After=docker.service
Requires=docker.service
After=network-online.target
Requires=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/rancher-agent
# Update profile
update:
group: stable
reboot-strategy: off
@donfirst

This comment has been minimized.

Copy link

donfirst commented Sep 8, 2016

Great stuff- but how to bootstrap Rancher server itself ?

@kweiberth

This comment has been minimized.

Copy link

kweiberth commented Jul 29, 2018

Thanks a lot for this example 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment