Created
September 3, 2024 15:16
-
-
Save jmarhee/70a57b6dddfb6ab70fdfced3c5b462e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - name: Import Kubernetes Cluster into Rancher | |
| hosts: localhost | |
| gather_facts: no | |
| vars: | |
| rancher_url: "https://rancher_url/v3" | |
| rancher_api_token: "bearer_token" | |
| cluster_name: "my-imported-cluster" | |
| tasks: | |
| - name: Create a new cluster in Rancher | |
| uri: | |
| url: "{{ rancher_url }}/clusters" | |
| method: POST | |
| headers: | |
| Authorization: "Bearer {{ rancher_api_token }}" | |
| Content-Type: "application/json" | |
| body: | | |
| { | |
| "type": "cluster", | |
| "name": "{{ cluster_name }}", | |
| "import": true | |
| } | |
| body_format: json | |
| return_content: yes | |
| register: cluster_response | |
| - name: Extract cluster ID | |
| set_fact: | |
| cluster_id: "{{ cluster_response.json.id }}" | |
| - name: Get import command | |
| uri: | |
| url: "{{ rancher_url }}/clusters/{{ cluster_id }}/importYaml" | |
| method: GET | |
| headers: | |
| Authorization: "Bearer {{ rancher_api_token }}" | |
| return_content: yes | |
| register: import_command_response | |
| - name: Save import command to file | |
| copy: | |
| content: "{{ import_command_response.content }}" | |
| dest: "./import_command.yaml" | |
| - name: Display import command | |
| debug: | |
| msg: "Import command saved to import_command.yaml." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment