Automating Rancher 2.x installation and configuration

Hi Rancher community,
we are trying to automate our Rancher installation und subsequent configuration. I haven’t been able to find any documentation on how to access and use the Rancher 2.0 API (v3) yet. Can you help us with some pointers?

Example:
We want to create a CI job to help us with testing Rancher 2.x installation and Rancher 2.x upgrades. Something like this:

  1. install Rancher 2.x (single node)
  2. add users, namespace and projects
  3. create node template
  4. create cluster
  5. deploy applications and test application
  6. remove cluster
  7. remove Rancher installation

We have only just started using Rancher, so apologies if I have overlooked stuff which has already been documented.

Cheers,
Thomas

That would be interesting for me, too. Has anyone already gone in that direction?
At least I want to give default password for admin, and automatic setup of the Rancher URL.

Cheers,
Damian

# Login token good for 1 minute
LOGINTOKEN=`curl -k -s 'https://127.0.0.1/v3-public/localProviders/local?action=login' -H 'content-type: application/json' --data-binary '{"username":"admin","password":"admin","ttl":60000}' | jq -r .token`

# Change password
curl -k -s 'https://127.0.0.1/v3/users?action=changepassword' -H 'Content-Type: application/json' -H "Authorization: Bearer $LOGINTOKEN" --data-binary '{"currentPassword":"admin","newPassword":"something better"}'

# Create API key good forever
APIKEY=`curl -k -s 'https://127.0.0.1/v3/token' -H 'Content-Type: application/json' -H "Authorization: Bearer $LOGINTOKEN" --data-binary '{"type":"token","description":"for scripts and stuff"}' | jq -r .token`
echo "API Key: ${APIKEY}"

# Set server-url
curl -k -s 'https://127.0.0.1/v3/settings/server-url' -H 'Content-Type: application/json' -H "Authorization: Bearer $APIKEY" -X PUT --data-binary '{"name":"server-url","value":"https://your-rancher.com/"}'

# Do whatever else you want

I’m doing it (in development at the moment). Check out https://rancher.com/docs/rancher/v2.x/en/quick-start-guide/deployment/digital-ocean-qs/ to get your started. It’s for digitalocean, but should give you a basic idea of the steps to take. The key files are the templates in the /files folder - they do the complex bit of configuring rancher, setting up the agents, etc.

For the rest, I’m using simple kubectl and helm commands.

Hope that helps,
Andy

ansible playbook has complete details how to automate it .

1 Like