postgresql - Length on None objects results in error
Hello,
I get the following when using postgresql role :
TASK [dalibo.essential.postgresql : Creating PostgreSQL directories] ***********
[ERROR]: Task failed: The filter plugin 'ansible.builtin.length' failed: object of type 'NoneType' has no len()
Task failed.
Origin: /home/robin/.ansible/collections/ansible_collections/dalibo/essential/roles/postgresql/tasks/main.yml:65:3
63 state: '{{ postgresql_packages_lock_state }}'
64 when: postgresql_with_contrib
65 - name: Creating PostgreSQL directories
^ column 3
<<< caused by >>>
The filter plugin 'ansible.builtin.length' failed: object of type 'NoneType' has no len()
Origin: /home/robin/.ansible/collections/ansible_collections/dalibo/essential/roles/postgresql/tasks/main.yml:78:9
76 - '{{ postgresql_data_directory | default(None) }}'
77 - '{{ postgresql_wal_directory | default(None) }}'
78 when: item|length>0
^ column 9
failed: [bd1] (item=None) => {"ansible_loop_var": "item", "changed": false, "item": null, "msg": "Task failed: The filter plugin 'ansible.builtin.length' failed: object of type 'NoneType' has no len()"}
It comes from postgresql/tasks/main.yml:65 :
Basically if you are using None when postgresql_*_directory variables are not set and it results in None | length.
Robin,