'Rancher: ranchercli switch context in script not interactively
I like to list all my contexts and switch to it from a command in my script, but it is interactively:
c:\\dist\\ranchercli\\rancher.exe context switch
NUMBER CLUSTER NAME PROJECT ID PROJECT NAME PROJECT DESCRIPTION
1 <all my projects listed>
2
3
4
:
Select a Project: (here I must enter a number, which is then saved to my cli2.json file)
my c:\.rancher\cli2.json only saves the active one,
If it is not active I get this error when accessing pods:
Error from server (Forbidden): pods is forbidden: User "u-vh3xagogyve" cannot list resource "pods" in API group ""
Nice it if was a direct ranchercli context set <project-id>
Solution 1:[1]
Found you can just use the projectid:
c:\dist\ranchercli\rancher.exe context switch c-r6dht:p-hz4fq
time="2022-02-23T14:26:40+01:00" level=info msg="Setting new context to project Unregulated"
time="2022-02-23T14:26:40+01:00" level=info msg="Saving config to \\.rancher\\cli2.json"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MortenB |
