# Script for initializing a cluster automatically

**URL:** <https://forums.suse.com/t/script-for-initializing-a-cluster-automatically/13166>\
**Category:** SUSE Rancher Prime\
**Created:** [January 31, 2019, 1:19am UTC](https://forums.suse.com/t/script-for-initializing-a-cluster-automatically/13166 "2019-01-31T01:19:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gonzalo.martinez](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@gonzalo.martinez](https://forums.suse.com/u/gonzalo.martinez)\
**Post date:** [January 31, 2019, 1:19am UTC](https://forums.suse.com/t/script-for-initializing-a-cluster-automatically/13166/1 "2019-01-31T01:19:21Z")

</div>

Hello guys.

I’m trying to make a script for creating a custom cluster automatically.

This is the project’s Github page: [https://github.com/ggMartinez/rancher\_cluster\_init](https://github.com/ggMartinez/rancher_cluster_init) (is based on the script rancher2customnodecmd.sh by superseb, just tried to improve it a little bit, and add some automatic stuff for using with Ansible).

It works at arround a 99%, the only issue I’m having is when trying to get the “nodeCommand” from the API to get the command to add nodes.

This is the code I’m getting:

`sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.1.6 --server --token XXXXXXXXX`

As you can see, there’s nothing for the “–server” parameter.

But, when I go to Rancher’s GUI, settings and advanced settings, the server URL is set right, and the value is perfect.

Also, when accesing to the endpoint “[https://127.0.0.1/v3/settings/server-url](https://127.0.0.1/v3/settings/server-url)” the value is correct.

This is how the script try to get the nodeCommand:

`curl -s 'https://127.0.0.1/v3/clusterregistrationtoken' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" --data-binary '{"type":"clusterRegistrationToken","clusterId":"'$CLUSTERID'"}' --insecure`

Is a minor issue, as I can just add it by hand, but it would be awesome for having it at 100%.

Obviously, anyone who wants to use/improve it, is welcome.

Best regards.

---

<div class="post-metadata">

**Author:** ![Mohkam](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/mohkam/32/7036_2.png) [@Mohkam](https://forums.suse.com/u/Mohkam)\
**Post date:** [December 29, 2020, 8:07pm UTC](https://forums.suse.com/t/script-for-initializing-a-cluster-automatically/13166/2 "2020-12-29T20:07:10Z")

</div>

i wonder if anyone was able to figureout this part.

---

<div class="post-metadata">

**Author:** ![superseb](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/superseb/32/2424_2.png) [@superseb](https://forums.suse.com/u/superseb)\
**Post date:** [January 5, 2021, 7:44am UTC](https://forums.suse.com/t/script-for-initializing-a-cluster-automatically/13166/3 "2021-01-05T07:44:03Z")

</div>

This has been used for a long time without issue, see [https://github.com/rancher/quickstart/blob/master/vagrant/scripts/configure\_rancher\_server.sh](https://github.com/rancher/quickstart/blob/master/vagrant/scripts/configure_rancher_server.sh) for an example. Let me know if you still run into issues when using this.
