From 222056a26fffa0693509c917702a6a068707c625 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Wed, 22 Jul 2020 01:18:30 +0200 Subject: [PATCH] Avoid to use 'length' filter with null value This error occurs when variables are null and DEFAULT_JINJA2_NATIVE is enabled: object of type 'NoneType' has no len() Change-Id: I7c69be60b846c03e30a0a6e8893bf2f3a3d5e5b8 --- playbooks/tox/pre-molecule.yaml | 2 +- roles/ensure-docker/tasks/main.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/playbooks/tox/pre-molecule.yaml b/playbooks/tox/pre-molecule.yaml index bca2f7f73..94be685cb 100644 --- a/playbooks/tox/pre-molecule.yaml +++ b/playbooks/tox/pre-molecule.yaml @@ -23,4 +23,4 @@ package: name: "{{ tox_molecule_packages }}" when: - - (tox_molecule_packages | length) > 0 + - tox_molecule_packages | default(false) diff --git a/roles/ensure-docker/tasks/main.yaml b/roles/ensure-docker/tasks/main.yaml index deb2bc520..dced53281 100644 --- a/roles/ensure-docker/tasks/main.yaml +++ b/roles/ensure-docker/tasks/main.yaml @@ -24,7 +24,7 @@ being gathered prior to executing this role. when: - not (docker_distro_vars_loaded | bool) - - (docker_distro_packages | length) < 1 + - not docker_distro_packages - name: Sanity check for distro install fail: @@ -34,7 +34,7 @@ required. Please check your settings. docker_distro_packages = {{ docker_distro_packages }} when: - - (docker_distro_packages | length) < 1 + - not docker_distro_packages - not (use_upstream_docker | bool) - name: Sanity check for upstream install @@ -45,7 +45,7 @@ required. Please check your settings. docker_upstream_distro_packages = {{ docker_upstream_distro_packages }} when: - - (docker_upstream_distro_packages | length) < 1 + - not docker_upstream_distro_packages - use_upstream_docker | bool - name: Sanity check for upstream install mirrors @@ -54,7 +54,7 @@ The variable `docker_mirror_base_url` is null, and upstream installation has been enabled. Check your settings. when: - - (docker_mirror_base_url | length) < 1 + - not docker_mirror_base_url - use_upstream_docker | bool - include_tasks: "docker-{{ (use_upstream_docker | bool) | ternary('upstream', 'distro') }}.yaml"