Build-operate workflow trial - allow for stop-starting cluster.

This commit is contained in:
Xan Manning 2019-12-20 19:03:27 +00:00
parent e8e5dbf45a
commit 717de81c7f
23 changed files with 91 additions and 24 deletions

View File

@ -45,6 +45,7 @@ consistency.
| Variable | Description | Default Value |
|--------------------------------|--------------------------------------------------------------------------|--------------------------------|
| `k3s_cluster_state` | State of cluster, options: installed, started, stopped, restarted. | installed |
| `k3s_release_version` | Use a specific version of k3s, eg. `v0.2.0`. Specify `false` for latest. | `false` |
| `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` |

View File

@ -1,5 +1,9 @@
---
# k3s cluster state, options: installed, started, stopped, restarted
# (default: installed)
k3s_cluster_state: installed
# Use a specific k3s version, if set to "false" we will get the latest
# k3s_release_version: v0.1.0
k3s_release_version: false

View File

@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
become: true
vars:
molecule_is_test: true
k3s_cluster_state: restarted
roles:
- role: xanmanning.k3s

View File

@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
become: true
vars:
molecule_is_test: true
k3s_cluster_state: started
roles:
- role: xanmanning.k3s

View File

@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
become: true
vars:
molecule_is_test: true
k3s_cluster_state: stopped
roles:
- role: xanmanning.k3s

View File

@ -1,27 +1,11 @@
---
- import_tasks: preconfigure-k3s.yml
- name: Check to see if k3s_cluster_state is a supported value
assert:
that:
- k3s_cluster_state in ['installed', 'started', 'stopped', 'restarted']
fail_msg: "k3s_cluster_state not valid. Check README.md for details."
success_msg: "k3s_cluster_state is valid."
when: k3s_cluster_state is defined
- include_tasks: install-docker-prerequisites-{{ ansible_os_family | lower }}.yml
when: k3s_use_docker
and ((k3s_control_workers)
or (not k3s_control_workers and not k3s_control_node))
- import_tasks: install-docker.yml
when: k3s_use_docker
and ((k3s_control_workers)
or (not k3s_control_workers and not k3s_control_node))
and ansible_distribution | replace(" ", "-") | lower not in ['amazon', 'suse', 'opensuse-leap']
- include_tasks: install-docker-{{ ansible_distribution | replace(" ", "-") | lower }}.yml
when: ansible_distribution | replace(" ", "-") | lower in ['amazon', 'suse', 'opensuse-leap']
- import_tasks: get-version.yml
when: k3s_release_version is not defined or not k3s_release_version
- import_tasks: download-k3s.yml
- import_tasks: install-k3s.yml
- import_tasks: configure-k3s-cluster.yml
when: play_hosts | length > 1
- import_tasks: state-{{ (k3s_cluster_state | lower) | default('installed') }}.yml

View File

@ -0,0 +1,7 @@
---
- name: Ensure k3s service is started
service:
name: k3s
state: started
enabled: true

View File

@ -0,0 +1,7 @@
---
- name: Ensure k3s service is stopped
service:
name: k3s
state: stopped
enabled: false

27
tasks/state-installed.yml Normal file
View File

@ -0,0 +1,27 @@
---
- import_tasks: preconfigure-k3s.yml
- include_tasks: build/install-docker-prerequisites-{{ ansible_os_family | lower }}.yml
when: k3s_use_docker
and ((k3s_control_workers)
or (not k3s_control_workers and not k3s_control_node))
- import_tasks: build/install-docker.yml
when: k3s_use_docker
and ((k3s_control_workers)
or (not k3s_control_workers and not k3s_control_node))
and ansible_distribution | replace(" ", "-") | lower not in ['amazon', 'suse', 'opensuse-leap']
- include_tasks: build/install-docker-{{ ansible_distribution | replace(" ", "-") | lower }}.yml
when: ansible_distribution | replace(" ", "-") | lower in ['amazon', 'suse', 'opensuse-leap']
- import_tasks: build/get-version.yml
when: k3s_release_version is not defined or not k3s_release_version
- import_tasks: build/download-k3s.yml
- import_tasks: build/install-k3s.yml
- import_tasks: build/configure-k3s-cluster.yml
when: play_hosts | length > 1

View File

@ -0,0 +1,4 @@
---
- import_tasks: operate/stop-k3s.yml
- import_tasks: operate/start-k3s.yml

3
tasks/state-started.yml Normal file
View File

@ -0,0 +1,3 @@
---
- import_tasks: operate/start-k3s.yml

3
tasks/state-stopped.yml Normal file
View File

@ -0,0 +1,3 @@
---
- import_tasks: operate/stop-k3s.yml