fix: make assert test for netaddr actually return a boolean (#13304)

* fix: make assert test for netaddr actually return a boolean

The netaddr test returns a string when the netaddr is installed. This makes
Ansible 2.20 angry. Here's a fix to make sure the true case also returns a
boolean instead of a string.

* fix: more fixes for non-boolean conditions

The `cloud_provider` assertion change is a little more involved. The only two
allowed values are "" and "external". Let's just always check the assertion
instead of skipping it when it's the default value, which is "".

All the other changes should be fairly obvious.
This commit is contained in:
Wren Turkal
2026-06-14 01:26:32 -07:00
committed by GitHub
parent 3011e19ccd
commit f2a7181f99
2 changed files with 6 additions and 7 deletions

View File

@@ -21,7 +21,7 @@
- name: "Check that python netaddr is installed"
assert:
msg: "Python netaddr is not present"
that: "'127.0.0.1' | ansible.utils.ipaddr"
that: "'127.0.0.1' | ansible.utils.ipaddr == '127.0.0.1'"
tags:
- check

View File

@@ -19,13 +19,13 @@
- name: Stop if kube_control_plane group is empty
assert:
that: groups.get( 'kube_control_plane' )
that: groups.get( 'kube_control_plane' ) != []
run_once: true
when: not ignore_assert_errors
- name: Stop if etcd group is empty in external etcd mode
assert:
that: groups.get('etcd') or etcd_deployment_type == 'kubeadm'
that: groups.get('etcd') != [] or etcd_deployment_type == 'kubeadm'
fail_msg: "Group 'etcd' cannot be empty in external etcd mode"
run_once: true
when:
@@ -79,9 +79,8 @@
- name: Check cloud_provider value
assert:
that: cloud_provider == 'external'
that: cloud_provider in ["", 'external']
when:
- cloud_provider
- not ignore_assert_errors
- name: Check external_cloud_provider value
@@ -94,7 +93,7 @@
- name: "Check that kube_service_addresses is a network range"
assert:
that:
- kube_service_addresses | ansible.utils.ipaddr('net')
- kube_service_addresses | ansible.utils.ipaddr('net') is not false
msg: "kube_service_addresses = '{{ kube_service_addresses }}' is not a valid network range"
run_once: true
when: ipv4_stack | bool
@@ -102,7 +101,7 @@
- name: "Check that kube_pods_subnet is a network range"
assert:
that:
- kube_pods_subnet | ansible.utils.ipaddr('net')
- kube_pods_subnet | ansible.utils.ipaddr('net') is not false
msg: "kube_pods_subnet = '{{ kube_pods_subnet }}' is not a valid network range"
run_once: true
when: ipv4_stack | bool