From bf077e7360f59a79113d42fa294f1d5caefe5171 Mon Sep 17 00:00:00 2001 From: Nikhil Kumar <69901234+NikKumar811@users.noreply.github.com> Date: Sun, 16 Aug 2026 19:54:17 +0530 Subject: [PATCH] Replace injected Ansible fact variables in network_plugin role (#13382) --- roles/network_plugin/calico/tasks/pre.yml | 12 ++++++------ roles/network_plugin/calico/tasks/repos.yml | 4 ++-- .../network_plugin/calico_defaults/defaults/main.yml | 2 +- roles/network_plugin/cilium/tasks/check.yml | 2 +- roles/network_plugin/flannel/tasks/main.yml | 2 +- roles/network_plugin/kube-router/tasks/annotate.yml | 6 +++--- roles/network_plugin/macvlan/handlers/main.yml | 8 ++++---- roles/network_plugin/macvlan/tasks/main.yml | 6 +++--- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/roles/network_plugin/calico/tasks/pre.yml b/roles/network_plugin/calico/tasks/pre.yml index f3f7797cb..920711640 100644 --- a/roles/network_plugin/calico/tasks/pre.yml +++ b/roles/network_plugin/calico/tasks/pre.yml @@ -24,12 +24,12 @@ include_vars: "{{ item }}" with_first_found: - files: - - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower | replace('/', '_') }}.yml" - - "{{ ansible_distribution | lower }}-{{ ansible_distribution_release }}.yml" - - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower | replace('/', '_') }}.yml" - - "{{ ansible_distribution | lower }}.yml" - - "{{ ansible_os_family | lower }}-{{ ansible_architecture }}.yml" - - "{{ ansible_os_family | lower }}.yml" + - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower | replace('/', '_') }}.yml" + - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_release'] }}.yml" + - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower | replace('/', '_') }}.yml" + - "{{ ansible_facts['distribution'] | lower }}.yml" + - "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['architecture'] }}.yml" + - "{{ ansible_facts['os_family'] | lower }}.yml" - defaults.yml paths: - ../vars diff --git a/roles/network_plugin/calico/tasks/repos.yml b/roles/network_plugin/calico/tasks/repos.yml index 7eba916bb..90183d999 100644 --- a/roles/network_plugin/calico/tasks/repos.yml +++ b/roles/network_plugin/calico/tasks/repos.yml @@ -16,6 +16,6 @@ enabled: true repo_gpgcheck: false when: - - ansible_os_family in ['RedHat'] - - ansible_distribution not in ['Fedora'] + - ansible_facts['os_family'] in ['RedHat'] + - ansible_facts['distribution'] not in ['Fedora'] - ansible_facts['distribution_major_version'] | int < 9 diff --git a/roles/network_plugin/calico_defaults/defaults/main.yml b/roles/network_plugin/calico_defaults/defaults/main.yml index 899a9fd71..bade3978a 100644 --- a/roles/network_plugin/calico_defaults/defaults/main.yml +++ b/roles/network_plugin/calico_defaults/defaults/main.yml @@ -105,7 +105,7 @@ calico_nftable_mode: "Disabled" # Calico Wireguard support calico_wireguard_enabled: false calico_wireguard_packages: [] -calico_wireguard_repo: https://download.copr.fedorainfracloud.org/results/jdoss/wireguard/epel-{{ ansible_distribution_major_version }}-$basearch/ +calico_wireguard_repo: https://download.copr.fedorainfracloud.org/results/jdoss/wireguard/epel-{{ ansible_facts['distribution_major_version'] }}-$basearch/ # If you want to use non default IP_AUTODETECTION_METHOD, IP6_AUTODETECTION_METHOD for calico node set this option to one of: # * can-reach=DESTINATION diff --git a/roles/network_plugin/cilium/tasks/check.yml b/roles/network_plugin/cilium/tasks/check.yml index 34bab4252..98aa37811 100644 --- a/roles/network_plugin/cilium/tasks/check.yml +++ b/roles/network_plugin/cilium/tasks/check.yml @@ -22,7 +22,7 @@ - name: Stop if kernel version is too low for Cilium Wireguard encryption assert: - that: ansible_kernel.split('-')[0] is version('5.6.0', '>=') + that: ansible_facts['kernel'].split('-')[0] is version('5.6.0', '>=') when: - kube_network_plugin == 'cilium' or cilium_deploy_additionally - cilium_encryption_enabled diff --git a/roles/network_plugin/flannel/tasks/main.yml b/roles/network_plugin/flannel/tasks/main.yml index 8fea555e4..8311485ee 100644 --- a/roles/network_plugin/flannel/tasks/main.yml +++ b/roles/network_plugin/flannel/tasks/main.yml @@ -2,7 +2,7 @@ - name: Flannel | Stop if kernel version is too low for Flannel Wireguard encryption assert: - that: ansible_kernel.split('-')[0] is version('5.6.0', '>=') + that: ansible_facts['kernel'].split('-')[0] is version('5.6.0', '>=') when: - kube_network_plugin == 'flannel' - flannel_backend_type == 'wireguard' diff --git a/roles/network_plugin/kube-router/tasks/annotate.yml b/roles/network_plugin/kube-router/tasks/annotate.yml index 9cb7f6e7c..d14c6b29f 100644 --- a/roles/network_plugin/kube-router/tasks/annotate.yml +++ b/roles/network_plugin/kube-router/tasks/annotate.yml @@ -1,20 +1,20 @@ --- - name: Kube-router | Add annotations on kube_control_plane - command: "{{ kubectl }} annotate --overwrite node {{ ansible_hostname }} {{ item }}" + command: "{{ kubectl }} annotate --overwrite node {{ ansible_facts['hostname'] }} {{ item }}" with_items: - "{{ kube_router_annotations_master }}" delegate_to: "{{ groups['kube_control_plane'][0] }}" when: kube_router_annotations_master is defined and 'kube_control_plane' in group_names - name: Kube-router | Add annotations on kube_node - command: "{{ kubectl }} annotate --overwrite node {{ ansible_hostname }} {{ item }}" + command: "{{ kubectl }} annotate --overwrite node {{ ansible_facts['hostname'] }} {{ item }}" with_items: - "{{ kube_router_annotations_node }}" delegate_to: "{{ groups['kube_control_plane'][0] }}" when: kube_router_annotations_node is defined and 'kube_node' in group_names - name: Kube-router | Add common annotations on all servers - command: "{{ kubectl }} annotate --overwrite node {{ ansible_hostname }} {{ item }}" + command: "{{ kubectl }} annotate --overwrite node {{ ansible_facts['hostname'] }} {{ item }}" with_items: - "{{ kube_router_annotations_all }}" delegate_to: "{{ groups['kube_control_plane'][0] }}" diff --git a/roles/network_plugin/macvlan/handlers/main.yml b/roles/network_plugin/macvlan/handlers/main.yml index e4844c221..9b4ed2d2c 100644 --- a/roles/network_plugin/macvlan/handlers/main.yml +++ b/roles/network_plugin/macvlan/handlers/main.yml @@ -3,13 +3,13 @@ service: # noqa: jinja[spacing] name: >- - {% if ansible_os_family == "RedHat" -%} + {% if ansible_facts['os_family'] == "RedHat" -%} network - {%- elif ansible_distribution == "Ubuntu" and ansible_distribution_release == "bionic" -%} + {%- elif ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_release'] == "bionic" -%} systemd-networkd - {%- elif ansible_os_family == "Debian" -%} + {%- elif ansible_facts['os_family'] == "Debian" -%} networking {%- endif %} state: restarted - when: not ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"] and kube_network_plugin not in ['calico'] + when: not ansible_facts['os_family'] in ["Flatcar", "Flatcar Container Linux by Kinvolk"] and kube_network_plugin not in ['calico'] listen: Macvlan | restart network diff --git a/roles/network_plugin/macvlan/tasks/main.yml b/roles/network_plugin/macvlan/tasks/main.yml index 1db02e0b4..54fe8d57d 100644 --- a/roles/network_plugin/macvlan/tasks/main.yml +++ b/roles/network_plugin/macvlan/tasks/main.yml @@ -25,10 +25,10 @@ dest: /etc/network/interfaces.d/60-mac0.cfg mode: "0644" notify: Macvlan | restart network - when: ansible_os_family in ["Debian"] + when: ansible_facts['os_family'] in ["Debian"] - name: Install macvlan config on RH distros - when: ansible_os_family == "RedHat" + when: ansible_facts['os_family'] == "RedHat" block: - name: Macvlan | Install macvlan script on centos copy: @@ -61,7 +61,7 @@ notify: Macvlan | restart network - name: Install macvlan config on Flatcar - when: ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"] + when: ansible_facts['os_family'] in ["Flatcar", "Flatcar Container Linux by Kinvolk"] block: - name: Macvlan | Install service nat via gateway on Flatcar Container Linux template: