From 2e6ce4165e01e3fb62656b5fb3816ef8688f4aac Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Fri, 28 Aug 2020 12:04:44 +0200 Subject: [PATCH] ansible-lint: fix error 602 Don't compare to empty string Change-Id: I3293a554ad4af76b47c73fe820e1809f561aefef --- .ansible-lint | 1 - .../roles/bifrost-cloud-config/tasks/main.yml | 4 ++-- .../bifrost-create-dib-image/tasks/main.yml | 10 +++++++--- .../bifrost-create-vm-nodes/tasks/main.yml | 20 ++++++++----------- .../tasks/bootstrap.yml | 6 ++++-- .../tasks/download_ipa_image.yml | 20 +++++++++++++------ .../bifrost-ironic-install/tasks/hw_types.yml | 8 ++++---- .../tasks/inspector_bootstrap.yml | 2 +- .../bifrost-ironic-install/tasks/start.yml | 4 +++- .../bifrost-ironic-install/tasks/validate.yml | 4 +++- .../roles/bifrost-pip-install/tasks/main.yml | 6 ++++-- 11 files changed, 50 insertions(+), 35 deletions(-) diff --git a/.ansible-lint b/.ansible-lint index c4ca66662..97be46e59 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -4,7 +4,6 @@ skip_list: - '301' # Commands should not change things if nothing needs doing - '502' # All tasks should be named - '601' # Don't compare to literal True/False - - '602' # Don't compare to empty string - '701' # meta/main.yml should contain relevant info - '702' # Tags must contain lowercase letters and digits only # NOTE(dtantsur): the following rules should likely stay excluded: diff --git a/playbooks/roles/bifrost-cloud-config/tasks/main.yml b/playbooks/roles/bifrost-cloud-config/tasks/main.yml index 2ec611730..d7d27ab92 100644 --- a/playbooks/roles/bifrost-cloud-config/tasks/main.yml +++ b/playbooks/roles/bifrost-cloud-config/tasks/main.yml @@ -59,7 +59,7 @@ set_fact: ironic_url: "{{ openstack_cloud.baremetal_endpoint_override }}" when: - - ironic_url | default("") == "" + - not ironic_url | default("") - openstack_cloud is defined - openstack_cloud.baremetal_endpoint_override is defined @@ -67,5 +67,5 @@ set_fact: ironic_url: "http://localhost:6385/" when: - - ironic_url | default("") == "" + - not ironic_url | default("") - noauth_mode | bool diff --git a/playbooks/roles/bifrost-create-dib-image/tasks/main.yml b/playbooks/roles/bifrost-create-dib-image/tasks/main.yml index 8578ecf24..60dcf5614 100644 --- a/playbooks/roles/bifrost-create-dib-image/tasks/main.yml +++ b/playbooks/roles/bifrost-create-dib-image/tasks/main.yml @@ -107,7 +107,9 @@ - name: "Build packages (-p) option for disk-image-create" set_fact: dib_packages_arg: "-p {{ dib_packages }}" - when: dib_packages is defined and dib_packages != "" + when: + - dib_packages is defined + - dib_packages | length > 0 - name: "Set default of Debian Buster if building debian and not explicitly set, overwride with dib_os_release setting" set_fact: dib_os_release: "buster" @@ -147,7 +149,7 @@ dib_env_vars_final: "{{ dib_env_vars_final | combine({'DIB_BLOCK_DEVICE_CONFIG': dib_partitioning}) }}" when: - dib_partitioning is defined - - dib_partitioning|length > 0 + - dib_partitioning | length > 0 - name: "Set partitioning information if set" slurp: src: "{{ partitioning_file }}" @@ -212,7 +214,9 @@ mode: u=rwX,g=rX,o=rX recurse: yes state: directory - when: http_boot_folder is defined and http_boot_folder != '' + when: + - http_boot_folder is defined + - http_boot_folder | length > 0 - name: "Restore proper context on created data for http_boot" command: restorecon -R {{ http_boot_folder }} when: (ansible_os_family == 'RedHat' or ansible_os_family == 'Suse') and diff --git a/playbooks/roles/bifrost-create-vm-nodes/tasks/main.yml b/playbooks/roles/bifrost-create-vm-nodes/tasks/main.yml index 8e9aadf40..cd6d7a59f 100644 --- a/playbooks/roles/bifrost-create-vm-nodes/tasks/main.yml +++ b/playbooks/roles/bifrost-create-vm-nodes/tasks/main.yml @@ -134,22 +134,18 @@ dest: "{{ baremetal_nodes_json }}" content: "{{ {'nodes': testvm_nodes_json} | to_nice_json }}" -- name: > - "Set file permissions such that the baremetal data file - can be read by the user executing Ansible" +- name: Ensure the baremetal data file can be read by the user executing Ansible file: path: "{{ baremetal_json_file }}" owner: "{{ ansible_env.SUDO_USER }}" - when: > - ansible_env.SUDO_USER is defined and - baremetal_json_file != "" + when: + - ansible_env.SUDO_USER is defined + - baremetal_json_file | length > 0 -- name: > - "Set file permissions such that the nodes json file - can be read by the user executing Ansible" +- name: Ensure the nodes json file can be read by the user executing Ansible file: path: "{{ baremetal_nodes_json }}" owner: "{{ ansible_env.SUDO_USER }}" - when: > - ansible_env.SUDO_USER is defined and - baremetal_nodes_json != "" + when: + - ansible_env.SUDO_USER is defined + - baremetal_nodes_json | length > 0 diff --git a/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml b/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml index 842359f2b..c71e04706 100644 --- a/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml +++ b/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml @@ -181,7 +181,7 @@ loop: - "{{ ironic_log_dir | default('') }}" - "{{ ironic_agent_deploy_logs_local_path | default('') }}" - when: item != "" + when: item | length > 0 - name: "Create ironic DB Schema" command: ironic-dbsync --config-file /etc/ironic/ironic.conf create_schema @@ -432,4 +432,6 @@ ansible_selinux.status == 'enabled' and ansible_selinux.mode == "enforcing" - name: "Configure remote logging" template: src=10-rsyslog-remote.conf.j2 dest=/etc/rsyslog.d/10-rsyslog-remote.conf - when: remote_syslog_server is defined and remote_syslog_server != "" + when: + - remote_syslog_server is defined + - remote_syslog_server | length > 0 diff --git a/playbooks/roles/bifrost-ironic-install/tasks/download_ipa_image.yml b/playbooks/roles/bifrost-ironic-install/tasks/download_ipa_image.yml index fb4fbcc9a..bdf115afb 100644 --- a/playbooks/roles/bifrost-ironic-install/tasks/download_ipa_image.yml +++ b/playbooks/roles/bifrost-ironic-install/tasks/download_ipa_image.yml @@ -51,11 +51,13 @@ when: not ipa_kernel_checksum_result is failed - fail: msg: "Failed to extract checksum for {{ ipa_kernel_upstream_url | basename }}" - when: not ipa_kernel_checksum_result is failed and parsed_ipa_kernel_checksum.stdout == "" + when: + - not ipa_kernel_checksum_result is failed + - not parsed_ipa_kernel_checksum.stdout - set_fact: ipa_kernel_checksum: "{{ ipa_kernel_upstream_checksum_algo }}:{{ parsed_ipa_kernel_checksum.stdout }}" when: not ipa_kernel_checksum_result is failed - when: ipa_kernel_upstream_checksum_url != "" + when: ipa_kernel_upstream_checksum_url | length > 0 - name: "Download IPA kernel" get_url: @@ -73,7 +75,9 @@ (ipa_kernel_download_done is failed) retries: 5 delay: 10 - when: update_ipa | bool or test_ipa_kernel_present.stat.exists == false + when: + - update_ipa | bool or + test_ipa_kernel_present.stat.exists == false - name: "Test if IPA image is present" stat: path={{ ipa_ramdisk }} @@ -111,11 +115,13 @@ when: not ipa_ramdisk_checksum_result is failed - fail: msg: "Failed to extract checksum for {{ ipa_ramdisk_upstream_url | basename }}" - when: not ipa_ramdisk_checksum_result is failed and parsed_ipa_ramdisk_checksum.stdout == "" + when: + - not ipa_ramdisk_checksum_result is failed + - not parsed_ipa_ramdisk_checksum.stdout - set_fact: ipa_ramdisk_checksum: "{{ ipa_ramdisk_upstream_checksum_algo }}:{{ parsed_ipa_ramdisk_checksum.stdout }}" when: not ipa_ramdisk_checksum_result is failed - when: ipa_ramdisk_upstream_checksum_url != "" + when: ipa_ramdisk_upstream_checksum_url | length > 0 - name: "Download IPA image" get_url: @@ -133,4 +139,6 @@ (ipa_ramdisk_download_done is failed and ipa_ramdisk_download_done.status_code is defined and ipa_ramdisk_download_done.status_code == 404) retries: 5 delay: 10 - when: update_ipa | bool or test_ipa_image_present.stat.exists == false + when: + - update_ipa | bool or + test_ipa_image_present.stat.exists == false diff --git a/playbooks/roles/bifrost-ironic-install/tasks/hw_types.yml b/playbooks/roles/bifrost-ironic-install/tasks/hw_types.yml index 197c1eff2..6f5774ae0 100644 --- a/playbooks/roles/bifrost-ironic-install/tasks/hw_types.yml +++ b/playbooks/roles/bifrost-ironic-install/tasks/hw_types.yml @@ -24,14 +24,14 @@ no-bios {%- if "ilo" in enabled_hardware_types -%},ilo{%- endif -%} {%- if "redfish" in enabled_hardware_types -%},redfish{%- endif -%} - when: enabled_bios_interfaces == "" + when: not enabled_bios_interfaces - name: "Configure boot interfaces if required" set_fact: enabled_boot_interfaces: >- ipxe,pxe {%- if "ilo" in enabled_hardware_types -%},ilo-virtual-media{%- endif -%} - when: enabled_boot_interfaces == "" + when: not enabled_boot_interfaces - name: "Configure management interfaces if required" set_fact: @@ -40,7 +40,7 @@ {%- if "ilo" in enabled_hardware_types -%},ilo{%- endif -%} {%- if "ipmi" in enabled_hardware_types -%},ipmitool{%- endif -%} {%- if "redfish" in enabled_hardware_types -%},redfish{%- endif -%} - when: enabled_management_interfaces == "" + when: not enabled_management_interfaces - name: "Configure power interfaces if required" set_fact: @@ -50,4 +50,4 @@ {%- if "ipmi" in enabled_hardware_types -%},ipmitool{%- endif -%} {%- if "redfish" in enabled_hardware_types -%},redfish{%- endif -%} {%- if enable_credential_less_deploy|bool -%},agent{%- endif -%} - when: enabled_power_interfaces == "" + when: not enabled_power_interfaces diff --git a/playbooks/roles/bifrost-ironic-install/tasks/inspector_bootstrap.yml b/playbooks/roles/bifrost-ironic-install/tasks/inspector_bootstrap.yml index caf7c3a8f..b7fb4b8cc 100644 --- a/playbooks/roles/bifrost-ironic-install/tasks/inspector_bootstrap.yml +++ b/playbooks/roles/bifrost-ironic-install/tasks/inspector_bootstrap.yml @@ -113,7 +113,7 @@ loop: - "{{ inspector_log_dir | default('') }}" - "{{ inspector_ramdisk_logs_local_path | default('') }}" - when: item != "" + when: item | length > 0 - name: "Upgrade inspector DB Schema" command: ironic-inspector-dbsync --config-file /etc/ironic-inspector/inspector.conf upgrade become: true diff --git a/playbooks/roles/bifrost-ironic-install/tasks/start.yml b/playbooks/roles/bifrost-ironic-install/tasks/start.yml index 3fcc9e76e..f00a6d72d 100644 --- a/playbooks/roles/bifrost-ironic-install/tasks/start.yml +++ b/playbooks/roles/bifrost-ironic-install/tasks/start.yml @@ -19,7 +19,9 @@ - name: "Ensure rsyslog is running with current config" service: name=rsyslog state=restarted - when: remote_syslog_server is defined and remote_syslog_server != "" + when: + - remote_syslog_server is defined + - remote_syslog_server | length > 0 - name: "Start database service" service: name={{ mysql_service_name }} state=started enabled=yes diff --git a/playbooks/roles/bifrost-ironic-install/tasks/validate.yml b/playbooks/roles/bifrost-ironic-install/tasks/validate.yml index 2e9ef0c0d..341a8a9ad 100644 --- a/playbooks/roles/bifrost-ironic-install/tasks/validate.yml +++ b/playbooks/roles/bifrost-ironic-install/tasks/validate.yml @@ -48,7 +48,9 @@ command: baremetal conductor list -f value -c Hostname environment: "{{ testing_env | combine(bifrost_venv_env) }}" register: conductor_list - failed_when: conductor_list.rc != 0 or conductor_list.stdout | trim == "" + failed_when: + - conductor_list.rc != 0 or + not conductor_list.stdout retries: 6 delay: 5 until: conductor_list is not failed diff --git a/playbooks/roles/bifrost-pip-install/tasks/main.yml b/playbooks/roles/bifrost-pip-install/tasks/main.yml index c353dc0bd..2a88dd84a 100644 --- a/playbooks/roles/bifrost-pip-install/tasks/main.yml +++ b/playbooks/roles/bifrost-pip-install/tasks/main.yml @@ -19,13 +19,15 @@ - name: "Check that sourcedir is provided with source_install" fail: msg: Source installation of requires sourcedir to be provided - when: source_install | bool and sourcedir | default('') == '' + when: + - source_install | bool + - not sourcedir - name: "Set extra_args if upper_constraints_file is defined" set_fact: constraints_extra_args: "{{ extra_args | default('') }} -c {{ upper_constraints_file }}" when: - - upper_constraints_file != '' + - upper_constraints_file | length > 0 # NOTE(dtantsur): constraining does not work correctly correctly with # source installation if the package itself is in constraints. - source_install | bool == false