Added the ability to set k3s_release_version as a release channel

This commit is contained in:
Xan Manning 2020-05-18 20:45:48 +01:00
parent e3301a59e4
commit 5ce8dec6ff
4 changed files with 36 additions and 9 deletions

View File

@ -46,7 +46,7 @@ consistency.
| Variable | Description | Default Value |
|----------------------------------|-------------------------------------------------------------------------------------|-----------------------------------------|
| `k3s_cluster_state` | State of cluster: installed, started, stopped, restarted, downloaded, uninstalled. | installed |
| `k3s_release_version` | Use a specific version of k3s, eg. `v0.2.0`. Specify `false` for latest. | `false` |
| `k3s_release_version` | Use a specific version of k3s, eg. `v0.2.0`. Specify `false` for stable. | `false` |
| `k3s_build_cluster` | When multiple `play_hosts` are available, attempt to cluster. Read notes below. | `true` |
| `k3s_github_url` | Set the GitHub URL to install k3s from. | https://github.com/rancher/k3s |
| `k3s_install_dir` | Installation directory for k3s. | `/usr/local/bin` |
@ -89,12 +89,23 @@ consistency.
#### Important note about `k3s_release_version`
If you do not set a `k3s_release_version` the latest version of k3s will be
installed. If you are developing against a specific version of k3s you must
ensure this is set in your Ansible configuration, eg:
If you do not set a `k3s_release_version` the latest version from the stable
channel of k3s will be installed. If you are developing against a specific
version of k3s you must ensure this is set in your Ansible configuration, eg:
```yaml
k3s_release_version: v0.2.0
k3s_release_version: v1.16.9+k3s1
```
It is also possible to install specific K3s "Channels", below are some
examples for `k3s_release_version`:
```yaml
k3s_release_version: false # defaults to 'stable' channel
k3s_release_version: stable # latest 'stable' release
k3s_release_version: testing # latest 'testing' release
k3s_release_version: v1.18 # latest v1.18 release
k3s_release_version: v1.17-testing # latest v1.17 testing release
```
#### Important note about `k3s_build_cluster`

View File

@ -1,12 +1,24 @@
---
- name: Get the latest release version from GitHub
- name: Ensure k3s_release_version is set to default if false
set_fact:
k3s_release_version: "{{ k3s_release_channel }}"
when: k3s_release_version is defined and not k3s_release_version
- name: Ensure the default release channel is set
set_fact:
k3s_release_channel: "{{ k3s_release_version | default('stable') }}"
- name: Get the latest release version from k3s.io
uri:
url: "{{ k3s_github_api_releases }}"
url: "{{ k3s_api_releases }}"
return_content: true
body_format: json
register: k3s_latest_release
- name: Ensure the release version is set as a fact
set_fact:
k3s_release_version: "{{ k3s_latest_release.json.tag_name }}"
k3s_release_version: "{{ item.latest }}"
loop: "{{ k3s_latest_release.json.data }}"
when: item.name == k3s_release_channel
and item.type == "channel"

View File

@ -7,7 +7,9 @@
- import_tasks: teardown/drain-and-remove-nodes.yml
- import_tasks: build/get-version.yml
when: k3s_release_version is not defined or not k3s_release_version
when: k3s_release_version is not defined
or not k3s_release_version
or k3s_release_version is not regex('\\+k3s[1-9]$')
- import_tasks: validate/main.yml

View File

@ -26,8 +26,10 @@ k3s_arch_lookup:
arch: arm
suffix: "-armhf"
k3s_release_channel: stable
k3s_github_api: "{{ k3s_github_url | replace('github.com', 'api.github.com') }}"
k3s_github_api_releases: "{{ k3s_github_api | replace('.com', '.com/repos') }}/releases/latest"
k3s_api_releases: https://update.k3s.io/v1-release/channels
k3s_github_download_url: "{{ k3s_github_url }}/releases/download"
k3s_controller_count: []