rancherrancher-cli

How can I automatically determine the version of Rancher?


Motivation. In the CI/CD pipeline of a project I am working on, I would like to use the Rancher CLI. To that end I need to install the version of the CLI that matches the version of the server. Concretely I'm looking to build a Docker image with the correct version of the CLI installed.

My findings/attempts. In the Rancher UI, I can click the version number in the sidebar to visit the /dashboard/about page, where download links for the CLI are shown. Unfortunately I cannot find out how to get those links automatically.

There is an old issue with a similar question, without reply, on GitHub.

There is a /v1/management.cattle.io.settings/cli-url-linux endpoint that returns the download link for the Linux binary, which I'm looking for. However, I've been unable to call that URL and get a response other than 403 Forbidden.

Apparently passing an Authentication header with the Bearer [token] value (where [token] is an API key generated on the /dashboard/account page) does not work, but I cannot figure out what does.

Question. How do I automatically find the version of Rancher via its API, so that I can download the matching CLI binary?


Solution

  • There is a setting called 'server-version'. You can query the value with rancher cli

    $ ./rancher login https://<SERVER_URL> --token <BEARER_TOKEN>
    
    ./rancher-v2.6.9/rancher settings get server-version -o json | jq .Setting.value -r
    

    With that you can check source code or deduce how API are called in the UI especially for various settings and then you can just use curl for achieving the same

    curl -H "Authorization: Bearer token-xxx:yyyyyy"  https://rancher_url/v1/management.cattle.io.settings/server-version | jq .value