feat: distribution is a dict and nodes and cluster are top level (#1288)

* feat: distribution is a dict and nodes and cluster are top level

Signed-off-by: Devin Buhl <devin@buhl.casa>

* chore: housekeeping

Signed-off-by: Devin Buhl <devin@buhl.casa>

---------

Signed-off-by: Devin Buhl <devin@buhl.casa>
This commit is contained in:
Devin Buhl authored and GitHub committed 2024-02-01 20:31:42 -05:00
1 parent cba35dc66a
commit 89673cd17b
55 files changed
+330 -302

No files matched your search

+1 -1
View File
@@ -1 +1 @@
main = lambda data: data.get("distribution") in ['k0s', 'k3s']
main = lambda data: data.get("distribution", {}).get("type", "k3s") in ["k0s", "k3s"]
@@ -1 +1 @@
main = lambda data: data.get("distribution") in ['k0s', 'k3s']
main = lambda data: data.get("distribution", {}).get("type", "k3s") in ["k0s", "k3s"]
@@ -1 +1 @@
main = lambda data: data.get("distribution") in ['k3s']
main = lambda data: data.get("distribution", {}).get("type", "k3s") in ["k3s"]
@@ -1 +1 @@
main = lambda data: data.get("distribution") in ['k3s']
main = lambda data: data.get("distribution", {}).get("type", "k3s") in ["k3s"]
@@ -1 +1,10 @@
main = lambda data: data.get("distribution") in ['k3s']
main = lambda data: (
data.get("distribution").get("type", "k3s") in ["k3s"] and
len(
list(
filter(
lambda item: "controller" in item and item["controller"] is False, data.get("nodes").get("inventory")
)
)
) > 0
)
@@ -3,17 +3,17 @@ kubernetes:
children:
master:
hosts:
{% for item in cluster.nodes.inventory %}
{% for item in nodes.inventory %}
{% if item.controller %}
"{{ item.name }}":
ansible_user: "{{ item.ssh_username }}"
ansible_host: "{{ item.address }}"
{% endif %}
{% endfor %}
{% if cluster.nodes.inventory | selectattr('controller', 'equalto', False) | list | length %}
{% if nodes.inventory | selectattr('controller', 'equalto', False) | list | length %}
worker:
hosts:
{% for item in cluster.nodes.inventory %}
{% for item in nodes.inventory %}
{% if not item.controller %}
"{{ item.name }}":
ansible_user: "{{ item.ssh_username }}"
@@ -1,4 +1,4 @@
{% if distribution in ['k3s'] %}
{% if distribution.type in ["k3s"] %}
---
- name: Cluster Installation
hosts: kubernetes
@@ -10,7 +10,7 @@
ansible.builtin.pause:
seconds: 5
tasks:
{% if distribution in ['k3s'] %}
{% if distribution.type in ["k3s"] %}
- name: Ensure Kubernetes is running
ansible.builtin.include_role:
name: xanmanning.k3s
@@ -21,9 +21,9 @@
- name: Upgrade kube-vip
ansible.builtin.template:
src: templates/kube-vip-ds.yaml.j2
{% if distribution in ['k3s'] %}
{% if distribution.type in ["k3s"] %}
dest: "{% raw %}{{ k3s_server_manifests_dir }}{% endraw %}/kube-vip-ds.yaml"
{% elif distribution in ['k0s'] %}
{% elif distribution.type in ["k0s"] %}
dest: "/var/lib/k0s/manifests/kube-vip/kube-vip-ds.yaml"
{% endif %}
mode: preserve
@@ -1,4 +1,4 @@
{% if distribution in ['k3s'] %}
{% if distribution.type in ["k3s"] %}
---
- name: Cluster Nuke
hosts: kubernetes
@@ -1,4 +1,4 @@
{% if distribution in ['k3s'] %}
{% if distribution.type in ["k3s"] %}
---
- name: Prepare System
hosts: kubernetes
@@ -62,8 +62,8 @@
mode: '0644'
dest: /etc/resolv.conf
content: |
search {{ cluster.nodes.search_domain|default('.', true) }}
{% for item in cluster.nodes.dns_servers %}
search {{ nodes.search_domain|default('.', true) }}
{% for item in nodes.dns_servers | default(['1.1.1.1', '1.0.0.1']) %}
nameserver {{ item }}
{% endfor %}
@@ -12,9 +12,9 @@
seconds: 5
tasks:
- name: Details
{% if distribution in ['k3s'] %}
{% if distribution.type in ["k3s"] %}
ansible.builtin.command: "k3s kubectl get node {% raw %}{{ inventory_hostname }}{% endraw %} -o json"
{% elif distribution in ['k0s'] %}
{% elif distribution.type in ["k0s"] %}
ansible.builtin.command: "k0s kubectl get node {% raw %}{{ inventory_hostname }}{% endraw %} -o json"
{% endif %}
register: kubectl_get_node
@@ -32,9 +32,9 @@
- name: Cordon
kubernetes.core.k8s_drain:
name: "{% raw %}{{ inventory_hostname }}{% endraw %}"
{% if distribution in ['k3s'] %}
{% if distribution.type in ["k3s"] %}
kubeconfig: /etc/rancher/k3s/k3s.yaml
{% elif distribution in ['k0s'] %}
{% elif distribution.type in ["k0s"] %}
kubeconfig: /var/lib/k0s/pki/admin.conf
{% endif %}
state: cordon
@@ -43,9 +43,9 @@
- name: Drain
kubernetes.core.k8s_drain:
name: "{% raw %}{{ inventory_hostname }}{% endraw %}"
{% if distribution in ['k3s'] %}
{% if distribution.type in ["k3s"] %}
kubeconfig: /etc/rancher/k3s/k3s.yaml
{% elif distribution in ['k0s'] %}
{% elif distribution.type in ["k0s"] %}
kubeconfig: /var/lib/k0s/pki/admin.conf
{% endif %}
state: drain
@@ -78,9 +78,9 @@
- name: Uncordon
kubernetes.core.k8s_drain:
name: "{% raw %}{{ inventory_hostname }}{% endraw %}"
{% if distribution in ['k3s'] %}
{% if distribution.type in ["k3s"] %}
kubeconfig: /etc/rancher/k3s/k3s.yaml
{% elif distribution in ['k0s'] %}
{% elif distribution.type in ["k0s"] %}
kubeconfig: /var/lib/k0s/pki/admin.conf
{% endif %}
state: uncordon
@@ -1 +1 @@
main = lambda data: data.get("distribution") in ['k3s']
main = lambda data: data.get("distribution", {}).get("type", "k3s") in ["k3s"]
@@ -1 +1 @@
main = lambda data: data.get("distribution") in ['k3s']
main = lambda data: data.get("distribution", {}).get("type", "k3s") in ["k3s"]
@@ -8,7 +8,7 @@ collections:
version: 8.3.0
- name: kubernetes.core
version: 3.0.0
{% if distribution in ['k3s'] %}
{% if distribution.type in ["k3s"] %}
roles:
- name: xanmanning.k3s
src: https://github.com/PyratLabs/ansible-role-k3s