[ansible-project] Re: lookup and default value

2016-09-22 Thread fanvalt
I cannot proceed that way when using a with_items loop.
I want to read parameters from a .csv file, and if the parameter does not 
exist , I want to set it to space.
i guess the issue is that instead of comparing the parameter value to an 
empty list, it does test if the parameter name is empty. 
Where am I doing wrong ?

  - set_fact:
"{{ item.name }}": "{{ lookup('csvfile', '{{ item.csvvar }} 
file=vars/{{ ansible_user }}.csv delimiter=; col={{ numinst }}') }}"
  with_items:
- { name: 'KARAFHTTPTIMEOUT', csvvar: 'KARAFHTTPTIMEOUT' }
- { name: 'dbType', csvvar: 'DBTYPE' }

- name: if empty set it to space
  set_fact:
"{{ item }}": " "
  with_items:
- KARAFHTTPTIMEOUT
- dbType
  when: item.0 is not defined

Regards

Le jeudi 8 septembre 2016 15:25:58 UTC+2, fanvalt a écrit :
>
> I did find out the way to bypass for the 2 cases:
>  - set_fact: port='1'
>when: port.0 is not defined or port ==''
>
>
> Le jeudi 8 septembre 2016 14:40:33 UTC+2, fanvalt a écrit :
>>
>> Hello,
>>
>> Is there a way to set a default value when using the lookup module for a 
>> csv file.
>>
>> Case 1:
>>
>> Here is the csv file:
>>
>> OPENHRPORT;;
>>
>> I would like to set the '1' value if the value in the csv file is not 
>> specified:
>>
>>vars:
>>  - port: "{{ lookup('csvfile', 'OPENHRPORT file=vars/test.csv 
>> delimiter=; col=1') | default('1') }}"
>>tasks:
>>  - debug: msg="port openhr {{ port }}"
>>
>>
>> But it returns the port varibale set to blank or unset, I would like it 
>> set to 1
>> "msg": "port openhr "
>>
>>
>> Case 2:
>> the csv file has only one key set:
>>
>> OPENHRPORT;;
>>
>> And I want to lookup at another key and set a default value if the key is 
>> not present in the csv file:
>>vars:
>>  - port: "{{ lookup('csvfile', 'OPDFT file=vars/test.csv delimiter=; 
>> col=1') | default('1') }}"
>>tasks:
>>  - debug: msg="port openhr {{ port }}"
>>
>> But it returns in the list bracket , I would expect it set to 1 
>>  "msg": "port openhr []"
>>
>> Could you give me any help on this lookup module and default value ?
>>
>> Regards,
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/93ade026-0877-4a54-a440-aa5ff065bf4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: lookup and default value

2016-09-08 Thread fanvalt
I did find out the way to bypass for the 2 cases:
 - set_fact: port='1'
   when: port.0 is not defined or port ==''


Le jeudi 8 septembre 2016 14:40:33 UTC+2, fanvalt a écrit :
>
> Hello,
>
> Is there a way to set a default value when using the lookup module for a 
> csv file.
>
> Case 1:
>
> Here is the csv file:
>
> OPENHRPORT;;
>
> I would like to set the '1' value if the value in the csv file is not 
> specified:
>
>vars:
>  - port: "{{ lookup('csvfile', 'OPENHRPORT file=vars/test.csv 
> delimiter=; col=1') | default('1') }}"
>tasks:
>  - debug: msg="port openhr {{ port }}"
>
>
> But it returns the port varibale set to blank or unset, I would like it 
> set to 1
> "msg": "port openhr "
>
>
> Case 2:
> the csv file has only one key set:
>
> OPENHRPORT;;
>
> And I want to lookup at another key and set a default value if the key is 
> not present in the csv file:
>vars:
>  - port: "{{ lookup('csvfile', 'OPDFT file=vars/test.csv delimiter=; 
> col=1') | default('1') }}"
>tasks:
>  - debug: msg="port openhr {{ port }}"
>
> But it returns in the list bracket , I would expect it set to 1 
>  "msg": "port openhr []"
>
> Could you give me any help on this lookup module and default value ?
>
> Regards,
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1eba25c8-8374-49d9-9d86-b7bbf8aab724%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: lookup and default value

2016-09-08 Thread fanvalt
I found out how to bypass the issue for case 1 by using:
- set_fact: port='1'
   when: port is not defined or port ==''

But it does not bypass the issue in case 2.
if port is [], empty list, what value of port should I test ?



Le jeudi 8 septembre 2016 14:40:33 UTC+2, fanvalt a écrit :
>
> Hello,
>
> Is there a way to set a default value when using the lookup module for a 
> csv file.
>
> Case 1:
>
> Here is the csv file:
>
> OPENHRPORT;;
>
> I would like to set the '1' value if the value in the csv file is not 
> specified:
>
>vars:
>  - port: "{{ lookup('csvfile', 'OPENHRPORT file=vars/test.csv 
> delimiter=; col=1') | default('1') }}"
>tasks:
>  - debug: msg="port openhr {{ port }}"
>
>
> But it returns the port varibale set to blank or unset, I would like it 
> set to 1
> "msg": "port openhr "
>
>
> Case 2:
> the csv file has only one key set:
>
> OPENHRPORT;;
>
> And I want to lookup at another key and set a default value if the key is 
> not present in the csv file:
>vars:
>  - port: "{{ lookup('csvfile', 'OPDFT file=vars/test.csv delimiter=; 
> col=1') | default('1') }}"
>tasks:
>  - debug: msg="port openhr {{ port }}"
>
> But it returns in the list bracket , I would expect it set to 1 
>  "msg": "port openhr []"
>
> Could you give me any help on this lookup module and default value ?
>
> Regards,
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3fc7aac4-ec50-48ac-aaf2-8d7a723b7465%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.