# how to verify all parameters are set and different from space in a csv file ?

**URL:** <https://forum.ansible.com/t/how-to-verify-all-parameters-are-set-and-different-from-space-in-a-csv-file/22651>\
**Category:** Ansible Project\
**Created:** [September 27, 2016, 9:44am UTC](https://forum.ansible.com/t/how-to-verify-all-parameters-are-set-and-different-from-space-in-a-csv-file/22651 "2016-09-27T09:44:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [September 27, 2016, 9:44am UTC](https://forum.ansible.com/t/how-to-verify-all-parameters-are-set-and-different-from-space-in-a-csv-file/22651/1 "2016-09-27T09:44:40Z")

</div>

Hello,

I read a csv file with the lookup command with a loop on the items:

tasks:

- set\_fact:  
“{{ item.name }}”: “{{ lookup(‘csvfile’, ‘{{ item.csvvar }} file=vars/fvaltat.csv delimiter=; col=1’) }}”  
with\_items:
- { name: ‘KARAFHTTPTIMEOUT’, csvvar: ‘TOTO’ }
- { name: ‘dbType’, csvvar: ‘DBTYPE’ }

How to check the variable does exist and is different from space  
I tried without success a fail … when :  
when: item.0 is not defined  
when: item.name is not defined  
when: item.name ==‘’  
I tried to use a register variable but I cannot find the way to test the register variable content.

Thanks for your help

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [September 27, 2016, 10:10am UTC](https://forum.ansible.com/t/how-to-verify-all-parameters-are-set-and-different-from-space-in-a-csv-file/22651/2 "2016-09-27T10:10:13Z")

</div>

The purpose is that the playbook fails if some parameters are not defined in the csv file

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [September 27, 2016, 10:44am UTC](https://forum.ansible.com/t/how-to-verify-all-parameters-are-set-and-different-from-space-in-a-csv-file/22651/3 "2016-09-27T10:44:53Z")

</div>

I understand the |default() can be used to run a loop only if the item is not an empty list,  
But I can’t find a way to proceed to quit the playbook if one parameter is missing:

vars: booleen: False

- set\_facts:  
booleen: True  
with\_items:
- “{{ KARAFHTTPTIMEOUT|default() }}”
- “{{ dbType|default() }}”

if all parameters are empty, booleen is False and I can use fail: … when booleen = False  
But if only one parameter is missing, booleen is true.

Thanks for helping: my purpose is to verify that all parameters are set in a csv file and to fail of one is missing.

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [September 27, 2016, 11:08am UTC](https://forum.ansible.com/t/how-to-verify-all-parameters-are-set-and-different-from-space-in-a-csv-file/22651/4 "2016-09-27T11:08:36Z")

</div>

I found a “bypass” way to proceed, but any suggestion is welcome:

- set\_fact:  
compte: "{{ compte|int +1 }} "  
with\_items:

- “{{ KARAFHTTPTIMEOUT|default() }}”

- “{{ dbType }}”

- fail:  
msg: “{{ 2 - compte|int}} parameters are missing”  
when: compte != 2

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [September 27, 2016, 11:27am UTC](https://forum.ansible.com/t/how-to-verify-all-parameters-are-set-and-different-from-space-in-a-csv-file/22651/5 "2016-09-27T11:27:42Z")

</div>

correcting the when clause:  
when: compte|int != 2

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [September 27, 2016, 11:57am UTC](https://forum.ansible.com/t/how-to-verify-all-parameters-are-set-and-different-from-space-in-a-csv-file/22651/6 "2016-09-27T11:57:23Z")

</div>

Finally this is still not OK as this bypass solution only works for ampty parameters.  
if parameters are set but not intialized, or set to space, this is not ok

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [September 27, 2016, 12:38pm UTC](https://forum.ansible.com/t/how-to-verify-all-parameters-are-set-and-different-from-space-in-a-csv-file/22651/7 "2016-09-27T12:38:56Z")

</div>

I had before counting for the parameters set:

- name: Si les parametres existent mais non renseignes, on les declare empty  
set\_fact:  
“{{ item }}” : ‘’  
with\_items:
- KARAFHTTPTIMEOUT
- dbType  
when: “{{ item }} is none or {{ item }}|trim == ‘’”
