Merge pull request #149 from onedr0p/main

feat: implement config.yaml.d
This commit is contained in:
Xan Manning 2021-09-08 19:03:17 +01:00 committed by GitHub
commit 25ca0ed8f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 83 additions and 24 deletions

View file

@ -59,25 +59,27 @@ below.
Below are variables that are set against all of the play hosts for environment Below are variables that are set against all of the play hosts for environment
consistency. These are generally cluster-level configuration. consistency. These are generally cluster-level configuration.
| Variable | Description | Default Value | | Variable | Description | Default Value |
|--------------------------------------|------------------------------------------------------------------------------------------------|--------------------------------| |--------------------------------------|--------------------------------------------------------------------------------------------|--------------------------------|
| `k3s_state` | State of k3s: installed, started, stopped, downloaded, uninstalled, validated. | installed | | `k3s_state` | State of k3s: installed, started, stopped, downloaded, uninstalled, validated. | installed |
| `k3s_release_version` | Use a specific version of k3s, eg. `v0.2.0`. Specify `false` for stable. | `false` | | `k3s_release_version` | Use a specific version of k3s, eg. `v0.2.0`. Specify `false` for stable. | `false` |
| `k3s_config_file` | Location of the k3s configuration file. | `/etc/rancher/k3s/config.yaml` | | `k3s_config_file` | Location of the k3s configuration file. | `/etc/rancher/k3s/config.yaml` |
| `k3s_build_cluster` | When multiple play hosts are available, attempt to cluster. Read notes below. | `true` | | `k3s_build_cluster` | When multiple play hosts are available, attempt to cluster. Read notes below. | `true` |
| `k3s_registration_address` | Fixed registration address for nodes. IP or FQDN. | NULL | | `k3s_registration_address` | Fixed registration address for nodes. IP or FQDN. | NULL |
| `k3s_github_url` | Set the GitHub URL to install k3s from. | https://github.com/k3s-io/k3s | | `k3s_github_url` | Set the GitHub URL to install k3s from. | https://github.com/k3s-io/k3s |
| `k3s_install_dir` | Installation directory for k3s. | `/usr/local/bin` | | `k3s_install_dir` | Installation directory for k3s. | `/usr/local/bin` |
| `k3s_install_hard_links` | Install using hard links rather than symbolic links. | `false` | | `k3s_install_hard_links` | Install using hard links rather than symbolic links. | `false` |
| `k3s_server_manifests_urls` | A list of URLs to deploy on the primary control plane. Read notes below. | [] | | `k3s_server_config_yaml_d_files` | A flat list of templates to supplement the `k3s_server` configuration. | [] |
| `k3s_server_manifests_templates` | A flat list of templates to deploy on the primary control plane. | [] | | `k3s_agent_config_yaml_d_files` | A flat list of templates to supplement the `k3s_agent` configuration. | [] |
| `k3s_server_pod_manifests_urls` | A list of URLs for installing static pod manifests on the control plane. Read notes below. | [] | | `k3s_server_manifests_urls` | A list of URLs to deploy on the primary control plane. Read notes below. | [] |
| `k3s_server_pod_manifests_templates` | A flat list of templates for installing static pod manifests on the control plane. | [] | | `k3s_server_manifests_templates` | A flat list of templates to deploy on the primary control plane. | [] |
| `k3s_use_experimental` | Allow the use of experimental features in k3s. | `false` | | `k3s_server_pod_manifests_urls` | A list of URLs for installing static pod manifests on the control plane. Read notes below. | [] |
| `k3s_use_unsupported_config` | Allow the use of unsupported configurations in k3s. | `false` | | `k3s_server_pod_manifests_templates` | A flat list of templates for installing static pod manifests on the control plane. | [] |
| `k3s_etcd_datastore` | Enable etcd embedded datastore (read notes below). | `false` | | `k3s_use_experimental` | Allow the use of experimental features in k3s. | `false` |
| `k3s_debug` | Enable debug logging on the k3s service. | `false` | | `k3s_use_unsupported_config` | Allow the use of unsupported configurations in k3s. | `false` |
| `k3s_registries` | Registries configuration file content. | `{ mirrors: {}, configs:{} }` | | `k3s_etcd_datastore` | Enable etcd embedded datastore (read notes below). | `false` |
| `k3s_debug` | Enable debug logging on the k3s service. | `false` |
| `k3s_registries` | Registries configuration file content. | `{ mirrors: {}, configs:{} }` |
### K3S Service Configuration ### K3S Service Configuration

View file

@ -12,8 +12,11 @@ k3s_state: installed
# k3s_release_version: v1.19.3 # k3s_release_version: v1.19.3
k3s_release_version: false k3s_release_version: false
# Loction of the k3s configuration file # Location of the k3s configuration file
k3s_config_file: /etc/rancher/k3s/config.yaml k3s_config_file: "/etc/rancher/k3s/config.yaml"
# Location of the k3s configuration directory
k3s_config_yaml_d_dir: "/etc/rancher/k3s/config.yaml.d"
# When multiple ansible_play_hosts are present, attempt to cluster the nodes. # When multiple ansible_play_hosts are present, attempt to cluster the nodes.
# Using false will create multiple standalone nodes. # Using false will create multiple standalone nodes.
@ -35,10 +38,16 @@ k3s_install_dir: /usr/local/bin
# Install using hard links rather than symbolic links # Install using hard links rather than symbolic links
k3s_install_hard_links: false k3s_install_hard_links: false
# A list of templates used for preconfigure the cluster. # A list of templates used for configuring the server.
k3s_server_config_yaml_d_files: []
# A list of templates used for configuring the agent.
k3s_agent_config_yaml_d_files: []
# A list of templates used for pre-configuring the cluster.
k3s_server_manifests_templates: [] k3s_server_manifests_templates: []
# A list of URLs used for preconfigure the cluster. # A list of URLs used for pre-configuring the cluster.
k3s_server_manifests_urls: [] k3s_server_manifests_urls: []
# - url: https://some/url/to/manifest.yml # - url: https://some/url/to/manifest.yml
# filename: manifest.yml # filename: manifest.yml

View file

@ -0,0 +1,18 @@
---
- name: Ensure that the config.yaml.d directory exists
ansible.builtin.file:
state: directory
path: "{{ k3s_config_yaml_d_dir }}"
mode: 0755
when: k3s_agent_config_yaml_d_files | length > 0
become: "{{ k3s_become_for_directory_creation | ternary(true, false, k3s_become_for_all) }}"
# https://github.com/k3s-io/k3s/pull/3162
- name: Ensure configuration files are copied to agents
ansible.builtin.template:
src: "{{ item }}"
dest: "{{ k3s_config_yaml_d_dir }}/{{ item | basename | replace('.j2','') }}"
mode: 0644
loop: "{{ k3s_agent_config_yaml_d_files }}"
become: "{{ k3s_become_for_directory_creation | ternary(true, false, k3s_become_for_all) }}"

View file

@ -0,0 +1,18 @@
---
- name: Ensure that the config.yaml.d directory exists
ansible.builtin.file:
state: directory
path: "{{ k3s_config_yaml_d_dir }}"
mode: 0755
when: k3s_server_config_yaml_d_files | length > 0
become: "{{ k3s_become_for_directory_creation | ternary(true, false, k3s_become_for_all) }}"
# https://github.com/k3s-io/k3s/pull/3162
- name: Ensure configuration files are copied to controllers
ansible.builtin.template:
src: "{{ item }}"
dest: "{{ k3s_config_yaml_d_dir }}/{{ item | basename | replace('.j2','') }}"
mode: 0644
loop: "{{ k3s_server_config_yaml_d_files }}"
become: "{{ k3s_become_for_directory_creation | ternary(true, false, k3s_become_for_all) }}"

View file

@ -54,6 +54,16 @@
- k3s_control_node - k3s_control_node
- k3s_server_pod_manifests_urls | length > 0 - k3s_server_pod_manifests_urls | length > 0
- import_tasks: build/preconfigure-k3s-server-config-yaml-d.yml
when:
- k3s_control_node
- k3s_server_config_yaml_d_files | length > 0
- import_tasks: build/preconfigure-k3s-agent-config-yaml-d.yml
when:
- not k3s_control_node
- k3s_agent_config_yaml_d_files | length > 0
- import_tasks: build/install-k3s.yml - import_tasks: build/install-k3s.yml
- name: Ensure containerd installation tasks are run - name: Ensure containerd installation tasks are run

View file

@ -74,7 +74,7 @@ k3s_systemd_unit_dir: "/etc/systemd/{{ k3s_systemd_context }}"
# Data directory location for k3s # Data directory location for k3s
k3s_data_dir: "{{ k3s_runtime_config['data-dir'] | default('/var/lib/rancher/k3s') }}" k3s_data_dir: "{{ k3s_runtime_config['data-dir'] | default('/var/lib/rancher/k3s') }}"
# Config directroy location for k3s # Config directory location for k3s
k3s_config_dir: "{{ k3s_config_file | dirname }}" k3s_config_dir: "{{ k3s_config_file | dirname }}"
# Directory for gathering the k3s token for clustering. I don't see this changing. # Directory for gathering the k3s token for clustering. I don't see this changing.
@ -99,6 +99,8 @@ k3s_check_packages: []
k3s_ensure_directories_exist: k3s_ensure_directories_exist:
- name: Config directory - name: Config directory
path: "{{ k3s_config_dir }}" path: "{{ k3s_config_dir }}"
- name: Config.yaml.d directory
path: "{{ k3s_config_yaml_d_dir }}"
- name: Systemd unit file directory - name: Systemd unit file directory
path: "{{ k3s_systemd_unit_dir }}" path: "{{ k3s_systemd_unit_dir }}"
- name: Data directory - name: Data directory