fanvalt  
                
                  
                    September 8, 2016, 12:40pm
                   
                  1 
               
             
            
              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’) }}” 
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:
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’) }}” 
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,
             
            
              
            
           
          
            
              
                fanvalt  
              
                  
                    September 8, 2016,  1:23pm
                   
                  2 
               
             
            
              I found out how to bypass the issue for case 1 by using:
set_fact: port=‘1’ 
 
But it does not bypass the issue in case 2.
             
            
              
            
           
          
            
              
                fanvalt  
              
                  
                    September 8, 2016,  1:25pm
                   
                  3 
               
             
            
              I did find out the way to bypass for the 2 cases:
set_fact: port=‘1’ 
 
             
            
              
            
           
          
            
              
                fanvalt  
              
                  
                    September 22, 2016,  7:20am
                   
                  4 
               
             
            
              I cannot proceed that way when using a with_items loop.
set_fact:
 
{ name: ‘KARAFHTTPTIMEOUT’, csvvar: ‘KARAFHTTPTIMEOUT’ }
 
{ name: ‘dbType’, csvvar: ‘DBTYPE’ }
 
name: if empty set it to space
 
KARAFHTTPTIMEOUT
 
dbType
 
 
when: item.0 is not defined
Regards