From 3d8dceebee346148c165696839c79ae462b7a474 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Fri, 30 Jan 2026 13:45:42 +0100 Subject: [PATCH] Ensure conditionals are proper booleans in roles In order to avoid broken conditionals error in Ansible we need to ensure that variables are proper booleans at all times. Change-Id: I693fb6d8f994b4712f9bedc528cbef63ea8abcb8 Signed-off-by: Dmitriy Rabotyagov --- roles/dynamic_address_fact/tasks/main.yml | 2 +- roles/glusterfs/tasks/glusterfs_install.yml | 4 ++-- roles/glusterfs/tasks/glusterfs_post_install.yml | 6 +++--- roles/mq_setup/tasks/main.yml | 9 ++++----- roles/openstack_resources/tasks/image.yml | 4 ++-- roles/openstack_resources/tasks/image_rotate.yml | 2 +- roles/openstack_resources/tasks/image_upload.yml | 3 ++- roles/openstack_resources/tasks/main.yml | 10 +++++----- roles/ssh_keypairs/tasks/main.yml | 6 +++--- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/roles/dynamic_address_fact/tasks/main.yml b/roles/dynamic_address_fact/tasks/main.yml index 169fbaaa..19bcbb4a 100644 --- a/roles/dynamic_address_fact/tasks/main.yml +++ b/roles/dynamic_address_fact/tasks/main.yml @@ -20,7 +20,7 @@ vars: default_network_interface_name: "{{ container_networks[network_address]['bridge'] | default }}" when: - - is_metal + - is_metal | bool - (dynamic_address_gather_filter is defined) or (default_network_interface_name | length > 0) tags: - common-address diff --git a/roles/glusterfs/tasks/glusterfs_install.yml b/roles/glusterfs/tasks/glusterfs_install.yml index e0e9cd8b..e8398b5f 100644 --- a/roles/glusterfs/tasks/glusterfs_install.yml +++ b/roles/glusterfs/tasks/glusterfs_install.yml @@ -45,7 +45,7 @@ content: "c /dev/fuse 0600 - - - 10:229" dest: "/etc/tmpfiles.d/openstack-ansible-glusterfs-server.conf" mode: "0644" - when: not (is_metal | default(False)) + when: not (is_metal | default(False)) | bool register: _glusterfs_server_tmpfiles - name: Restart systemd-tmpfiles-setup-dev @@ -54,7 +54,7 @@ enabled: true state: restarted when: - - not (is_metal | default(False)) + - not (is_metal | default(False)) | bool - _glusterfs_server_tmpfiles is changed - name: Start glusterfs server diff --git a/roles/glusterfs/tasks/glusterfs_post_install.yml b/roles/glusterfs/tasks/glusterfs_post_install.yml index 605ae4c1..65f4baae 100644 --- a/roles/glusterfs/tasks/glusterfs_post_install.yml +++ b/roles/glusterfs/tasks/glusterfs_post_install.yml @@ -16,7 +16,7 @@ - name: Create gluster peers gluster.gluster.gluster_peer: nodes: "{{ glusterfs_server_cluster_members }}" - when: _glusterfs_is_bootstrap_host + when: _glusterfs_is_bootstrap_host | bool - name: Ensure glusterfs backing directory exists ansible.builtin.file: @@ -43,7 +43,7 @@ when: - _backing_dir_create is changed - _brick_online_status.rc == 0 - - (_brick_online_status.stdout_lines | select('contains', 'Online'))[0] | regex_search('N') + - (_brick_online_status.stdout_lines | select('contains', 'Online'))[0] | regex_search('N') is not none with_items: - gluster volume reset-brick {{ glusterfs_server_volume_name }} {{ brick }} start - gluster volume reset-brick {{ glusterfs_server_volume_name }} {{ brick }} {{ brick }} commit force @@ -52,4 +52,4 @@ ansible.builtin.include_tasks: file: glusterfs_post_install_brick.yml when: - - _glusterfs_is_bootstrap_host + - _glusterfs_is_bootstrap_host | bool diff --git a/roles/mq_setup/tasks/main.yml b/roles/mq_setup/tasks/main.yml index 049dd30b..2c438d00 100644 --- a/roles/mq_setup/tasks/main.yml +++ b/roles/mq_setup/tasks/main.yml @@ -34,7 +34,7 @@ loop_control: loop_var: __mq_vhost when: - - "(_oslomsg_rpc_configure | default(_oslomsg_rpc_transport is defined))" + - "(_oslomsg_rpc_configure | default(_oslomsg_rpc_transport is defined) | bool)" - "(_oslomsg_rpc_transport is defined) and (_oslomsg_rpc_transport == 'rabbit')" tags: - common-rabbitmq @@ -42,7 +42,7 @@ - name: Setup Notify MQ Service (RabbitMQ) delegate_to: "{{ _oslomsg_notify_setup_host }}" when: - - "(_oslomsg_notify_configure | default(_oslomsg_notify_transport is defined))" + - "(_oslomsg_notify_configure | default(_oslomsg_notify_transport is defined) | bool)" - "(_oslomsg_notify_transport is defined) and (_oslomsg_notify_transport == 'rabbit')" tags: - common-rabbitmq @@ -58,7 +58,7 @@ - (_oslomsg_rpc_vhost is undefined) or (_oslomsg_notify_vhost != _oslomsg_rpc_vhost) or (_oslomsg_notify_setup_host != _oslomsg_rpc_setup_host) or - not (_oslomsg_rpc_configure | default(_oslomsg_rpc_transport is defined)) + not (_oslomsg_rpc_configure | default(_oslomsg_rpc_transport is defined) | bool) - name: Setup Notify user vars: @@ -73,5 +73,4 @@ - (_oslomsg_rpc_userid is undefined) or (_oslomsg_notify_userid != _oslomsg_rpc_userid) or (_oslomsg_notify_setup_host != _oslomsg_rpc_setup_host) or - not (_oslomsg_rpc_configure | default(_oslomsg_rpc_transport is defined)) - + not (_oslomsg_rpc_configure | default(_oslomsg_rpc_transport is defined) | bool) diff --git a/roles/openstack_resources/tasks/image.yml b/roles/openstack_resources/tasks/image.yml index f4b905b1..d260fac8 100644 --- a/roles/openstack_resources/tasks/image.yml +++ b/roles/openstack_resources/tasks/image.yml @@ -18,8 +18,8 @@ cloud: "{{ openstack_resources_cloud_name }}" interface: "{{ openstack_resources_interface }}" when: - - openstack_resources_image['images'] | selectattr('checksum', 'defined') - - not (openstack_resources_image['image_force_upload'] | default(false)) + - openstack_resources_image['images'] | selectattr('checksum', 'defined') | length > 0 + - not (openstack_resources_image['image_force_upload'] | default(false)) | bool register: existing_images - name: Upload images diff --git a/roles/openstack_resources/tasks/image_rotate.yml b/roles/openstack_resources/tasks/image_rotate.yml index c4297eff..11a97953 100644 --- a/roles/openstack_resources/tasks/image_rotate.yml +++ b/roles/openstack_resources/tasks/image_rotate.yml @@ -31,7 +31,7 @@ - name: Remove outdated images when: - "'keep_copies' in image" - - item + - item | length > 0 - not item['is_protected'] - item['visibility'] == image['hide_method'] openstack.cloud.image: diff --git a/roles/openstack_resources/tasks/image_upload.yml b/roles/openstack_resources/tasks/image_upload.yml index ec5e6870..6f28e412 100644 --- a/roles/openstack_resources/tasks/image_upload.yml +++ b/roles/openstack_resources/tasks/image_upload.yml @@ -26,7 +26,8 @@ - name: Downloading image from remote url vars: images_for_download: "{{ images | selectattr('url', 'defined') }}" - when: images_for_download + when: + - images_for_download | length > 0 block: - name: Create temporary dir for the image download ansible.builtin.tempfile: diff --git a/roles/openstack_resources/tasks/main.yml b/roles/openstack_resources/tasks/main.yml index 398104df..021732b2 100644 --- a/roles/openstack_resources/tasks/main.yml +++ b/roles/openstack_resources/tasks/main.yml @@ -19,7 +19,7 @@ apply: tags: - common-service - when: openstack_resources_identity + when: openstack_resources_identity | length > 0 tags: - common-service @@ -36,7 +36,7 @@ tags: - compute-resources when: - - openstack_resources_compute + - openstack_resources_compute | length > 0 - name: Add network resources ansible.builtin.include_tasks: @@ -49,7 +49,7 @@ tags: - network-resources when: - - openstack_resources_network + - openstack_resources_network | length > 0 - name: Add image resources ansible.builtin.include_tasks: @@ -62,7 +62,7 @@ tags: - image-resources when: - - openstack_resources_image + - openstack_resources_image | length > 0 - name: Add coe resources ansible.builtin.include_tasks: @@ -75,4 +75,4 @@ tags: - coe-resources when: - - openstack_resources_coe + - openstack_resources_coe | length > 0 diff --git a/roles/ssh_keypairs/tasks/main.yml b/roles/ssh_keypairs/tasks/main.yml index 23c129ff..1a9b6ff5 100644 --- a/roles/ssh_keypairs/tasks/main.yml +++ b/roles/ssh_keypairs/tasks/main.yml @@ -18,7 +18,7 @@ file: "{{ ssh_keypairs_method ~ '_keypair.yml' }}" - name: Create keypairs - when: ssh_keypairs_create_keys + when: ssh_keypairs_create_keys | bool block: - name: Create keypair directories ansible.builtin.file: @@ -43,9 +43,9 @@ - name: Install ssh server certificate authorities ansible.builtin.include_tasks: "{{ ssh_keypairs_method }}/install_ssh_ca.yml" when: - - ssh_keypairs_install_authorities + - ssh_keypairs_install_authorities | bool - name: Install ssh keys ansible.builtin.include_tasks: "{{ ssh_keypairs_method }}/install_ssh_key.yml" when: - - ssh_keypairs_install_keypairs + - ssh_keypairs_install_keypairs | bool