fix: use lists for cidr vars and node ip

This commit is contained in:
Robert Kaussow 2024-08-17 17:17:12 +02:00
parent d583082ffa
commit b14bd45c2a
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
5 changed files with 17 additions and 13 deletions

View File

@ -12,7 +12,8 @@ k3s_packages_extra: []
k3s_reset: False
k3s_token: "secure-token"
k3s_node_name: "{{ ansible_hostname }}"
k3s_node_ip: "{{ ansible_default_ipv4.address }}"
k3s_node_ip:
- "{{ ansible_default_ipv4.address }}"
k3s_init_log_enabled: False
k3s_selinux_enabled: False
k3s_protect_kernel_defaults: False
@ -20,8 +21,10 @@ k3s_protect_kernel_defaults: False
k3s_server: True
k3s_server_bind_ip: "0.0.0.0"
k3s_server_cluster_domain: "cluster.local"
k3s_server_cluster_cidr: "10.42.0.0/16"
k3s_server_service_cidr: "10.43.0.0/16"
k3s_server_cluster_cidr:
- "10.42.0.0/16"
k3s_server_service_cidr:
- "10.43.0.0/16"
k3s_server_service_node_port_range: "30000-32767"
k3s_server_cluster_dns: "10.43.0.10"
k3s_server_nodes:

View File

@ -50,7 +50,8 @@
pre_tasks:
- name: Override host variables
ansible.builtin.set_fact:
k3s_node_ip: "{{ ansible_default_ipv4.address }}"
k3s_node_ip:
- "{{ ansible_default_ipv4.address }}"
roles:
- role: xoxys.kernel
- role: xoxys.k3s

View File

@ -67,7 +67,7 @@
state: patched
definition:
metadata:
labels: "{{ (__k3s_node_lables['control'] if k3s_server | bool else __k3s_node_lables['worker']) | combine(__k3s_node_lables['general'], k3s_node_labels) }}"
labels: "{{ (__k3s_node_lables['control'] if k3s_server | bool else __k3s_node_lables['worker']) | combine(__k3s_node_lables['general'], 66) }}"
delegate_to: "{{ hostvars[k3s_server_nodes[0]]['inventory_hostname'] }}"
- name: Patch existing resources

View File

@ -1,12 +1,12 @@
#jinja2: lstrip_blocks: True
---
{% set __k3s_kube_apiserver_arg = lookup('template', '_internal/apiserver-arg.yaml.j2') | from_yaml %}
{% set __k3s_kube_controller_manager_arg = lookup('template', '_internal/kube-controller-manager-arg.yaml.j2') | from_yaml %}
{% set __k3s_kubelet_arg = lookup('template', '_internal/kubelet-arg.yaml.j2') | from_yaml %}
{% set __k3s_node_taint = lookup('template', '_internal/node-taint.yaml.j2') | from_yaml %}
{% set __k3s_kube_apiserver_arg = lookup("template", "_internal/apiserver-arg.yaml.j2") | from_yaml %}
{% set __k3s_kube_controller_manager_arg = lookup("template", "_internal/kube-controller-manager-arg.yaml.j2") | from_yaml %}
{% set __k3s_kubelet_arg = lookup("template", "_internal/kubelet-arg.yaml.j2") | from_yaml %}
{% set __k3s_node_taint = lookup("template", "_internal/node-taint.yaml.j2") | from_yaml %}
token: "{{ k3s_token }}"
node-name: "{{ k3s_node_name }}"
node-ip: "{{ k3s_node_ip }}"
node-ip: "{{ k3s_node_ip | join(',') }}"
{% if __k3s_node_taint is iterable %}
node-taint:
{{ __k3s_node_taint | to_nice_yaml(indent=2) | indent(2, False) }}
@ -21,9 +21,9 @@ protect-kernel-defaults: {{ k3s_protect_kernel_defaults | bool | lower }}
{% if k3s_server | bool %}
bind-address: "{{ k3s_server_bind_ip }}"
cluster-domain: "{{ k3s_server_cluster_domain }}"
cluster-cidr: "{{ k3s_server_cluster_cidr }}"
cluster-cidr: "{{ k3s_server_cluster_cidr | join(',') }}"
cluster-dns: "{{ k3s_server_cluster_dns }}"
service-cidr: "{{ k3s_server_service_cidr }}"
service-cidr: "{{ k3s_server_service_cidr | join(',') }}"
service-node-port-range: "{{ k3s_server_service_node_port_range }}"
secrets-encryption: True
write-kubeconfig: "{{ __k3s_config_dir }}/k3s.yaml"

View File

@ -1,6 +1,6 @@
---
__k3s_binary: /usr/local/bin/k3s
__k3s_server_ip: "{{ hostvars[k3s_server_nodes[0]].k3s_node_ip }}"
__k3s_server_ip: "{{ hostvars[k3s_server_nodes[0]].k3s_node_ip | first }}"
__k3s_server_init_args: >-
{% if k3s_server_nodes | length > 1 %}