diff --git a/.travis.yml b/.travis.yml index 4b1b599..091aa53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,10 @@ env: - MOLECULE_DISTRO: geerlingguy/docker-fedora31-ansible:latest MOLECULE_PLAYBOOK: playbook-no-deploy.yml + # Test auto deploying manifests + - MOLECULE_DISTRO: geerlingguy/docker-ubuntu1804-ansible:latest + MOLECULE_PLAYBOOK: playbook-auto-deploying-manifests.yml + # Test multiple masters in control plane with PostgreSQL - MOLECULE_DISTRO: geerlingguy/docker-centos8-ansible:latest MOLECULE_SCENARIO: highavailability diff --git a/README.md b/README.md index 6df7735..ac75fb6 100644 --- a/README.md +++ b/README.md @@ -112,19 +112,22 @@ Please note that this may potentially break setting up agents. Below are variables that are set against specific hosts in your inventory. -| Variable | Description | Default Value | -|-----------------------------|--------------------------------------------------------------------------|------------------------| -| `k3s_control_node` | Define the host as a control plane node, (True/False). | `false` | -| `k3s_node_name` | Define the name of this node. | `$(hostname)` | -| `k3s_node_id` | Define the ID of this node. | _NULL_ | -| `k3s_flannel_interface` | Define the flannel proxy interface for this node. | _NULL_ | -| `k3s_bind_address` | Define the bind address for this node. | localhost | -| `k3s_node_ip_address` | IP Address to advertise for this node. | _NULL_ | -| `k3s_node_external_address` | External IP Address to advertise for this node. | _NULL_ | -| `k3s_node_labels` | List of node labels. | _NULL_ | -| `k3s_node_taints` | List of node taints. | _NULL_ | -| `k3s_node_data_dir` | Folder to hold state. | `/var/lib/rancher/k3s` | -| `k3s_tls_san` | Add additional hosname or IP as Subject Alternate Name in the TLS cert. | _NULL_ | +| Variable | Description | Default Value | +|----------------------------------|--------------------------------------------------------------------------|-----------------------------------------| +| `k3s_control_node` | Define the host as a control plane node, (True/False). | `false` | +| `k3s_node_name` | Define the name of this node. | `$(hostname)` | +| `k3s_node_id` | Define the ID of this node. | _NULL_ | +| `k3s_flannel_interface` | Define the flannel proxy interface for this node. | _NULL_ | +| `k3s_bind_address` | Define the bind address for this node. | localhost | +| `k3s_node_ip_address` | IP Address to advertise for this node. | _NULL_ | +| `k3s_node_external_address` | External IP Address to advertise for this node. | _NULL_ | +| `k3s_node_labels` | List of node labels. | _NULL_ | +| `k3s_node_taints` | List of node taints. | _NULL_ | +| `k3s_node_data_dir` | Folder to hold state. | `/var/lib/rancher/k3s` | +| `k3s_tls_san` | Add additional hosname or IP as Subject Alternate Name in the TLS cert. | _NULL_ | +| `k3s_server_manifests_dir` | Path for place the `k3s_server_manifests_templates`. | `/var/lib/rancher/k3s/server/manifests` | +| `k3s_server_manifests_templates` | A list of Auto-Deploying Manifests Templates. | [] | + #### Important note about `k3s_control_node` and High Availability (HA) diff --git a/defaults/main.yml b/defaults/main.yml index 1d077b7..330727a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -14,6 +14,13 @@ k3s_github_url: https://github.com/rancher/k3s # Installation directory for k3s k3s_install_dir: /usr/local/bin +# Path for additional Kubernetes Manifests +# https://rancher.com/docs/k3s/latest/en/advanced/#auto-deploying-manifests +k3s_server_manifests_dir: /var/lib/rancher/k3s/server/manifests + +# A list of templates used for preconfigure the cluster. +k3s_server_manifests_templates: [] + # Use experimental features in k3s? k3s_use_experimental: false diff --git a/molecule/default/playbook-auto-deploying-manifests.yml b/molecule/default/playbook-auto-deploying-manifests.yml new file mode 100644 index 0000000..72b26be --- /dev/null +++ b/molecule/default/playbook-auto-deploying-manifests.yml @@ -0,0 +1,10 @@ +--- +- name: Converge + hosts: all + become: true + vars: + molecule_is_test: true + k3s_server_manifests_templates: + - "molecule/default/templates/00-ns-monitoring.yml.j2" + roles: + - role: xanmanning.k3s diff --git a/molecule/default/templates/00-ns-monitoring.yml.j2 b/molecule/default/templates/00-ns-monitoring.yml.j2 new file mode 100644 index 0000000..d325236 --- /dev/null +++ b/molecule/default/templates/00-ns-monitoring.yml.j2 @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: monitoring diff --git a/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml new file mode 100644 index 0000000..719cd20 --- /dev/null +++ b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml @@ -0,0 +1,14 @@ +--- + +- name: Ensure that the manifests directory exists, if required + file: + state: directory + path: "{{ k3s_server_manifests_dir }}" + when: k3s_server_manifests_templates | length > 0 + +# https://rancher.com/docs/k3s/latest/en/advanced/#auto-deploying-manifests +- name: Copy Auto-Deploying Manifests to Cluster + template: + src: "{{ item }}" + dest: "{{ k3s_server_manifests_dir }}/{{ item | basename | replace('.j2','') }}" + loop: "{{ k3s_server_manifests_templates }}" diff --git a/tasks/state-installed.yml b/tasks/state-installed.yml index 1a71b74..d85396b 100644 --- a/tasks/state-installed.yml +++ b/tasks/state-installed.yml @@ -28,6 +28,8 @@ - import_tasks: build/download-k3s.yml +- import_tasks: build/preconfigure-k3s-auto-deploying-manifests.yml + - import_tasks: build/install-k3s.yml - import_tasks: build/configure-k3s-cluster.yml