# Creating config files from .csv files

**URL:** <https://forum.ansible.com/t/creating-config-files-from-csv-files/26084>\
**Category:** Ansible Project\
**Created:** [November 20, 2017, 7:26pm UTC](https://forum.ansible.com/t/creating-config-files-from-csv-files/26084 "2017-11-20T19:26:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Davidson](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tim\_Davidson](https://forum.ansible.com/u/Tim_Davidson)\
**Post date:** [November 20, 2017, 7:26pm UTC](https://forum.ansible.com/t/creating-config-files-from-csv-files/26084/1 "2017-11-20T19:26:39Z")

</div>

Hello,

I’m attempting to create config files from one or more csv files. I want the name of each config file to be the hostname (first field) within each record read from the csv files. I think I’m close, but I can’t seem to find the right reference for that hostname value.

> # This task is just for debugging
> 
> - name: Read the csv files
> 
> debug:
> 
> msg= “{{ item.split(‘,’)[0] }}”
> 
> with\_lines: “egrep -v ‘^name’ /home/sysadmin/TimsTest1/roles/opengear/files/\*.csv”

Sample output:

TASK [opengear : Read the csv files] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> (item=/home/sysadmin/TimsTest1/roles/opengear/files/USCAL3-File1.csv:USCAL3-IM7208-01,The Lab ,America/New\_York,10.103.50.6,10.9.167.218,10.10.61.71,10.103.50.1,255.255.255.224,networkservices@me.com,MyAddressHere Flr-3,USCAL3-RW4451-01-03,USCAL3-RW4451-02-03,USCAL3-AS3650-01-03,USCAL3-AS3650-02-03,Port 5,RTR-A,RTR-B,Port 8) =\> {  
“item”: “/home/sysadmin/TimsTest1/roles/opengear/files/USCFC3-File1.csv:USCFC3-IM7208-01,The Lab ,America/New\_York,10.103.50.6,10.9.167.218,10.10.61.71,10.103.50.1,255.255.255.224,networkservices@me.com,MyAddressHere Flr-3,USCAL3-RW4451-01-03,USCAL3-RW4451-02-03,USCAL3-AS3650-01-03,USCAL3-AS3650-02-03,Port 5,RTR-A,RTR-B,Port 8”,  
“msg”: “”  
}

> # Grab the files from the csv files and combine with the template
> 
> - name: Create OpenGear device configs
> 
> template:
> 
> src: “opengear8port.j2”
> 
> dest: “{{ item.split(‘,’)[0] }}.xml”
> 
> with\_lines: “egrep -v ‘^name’ /home/sysadmin/TimsTest1/roles/opengear/files/\*.csv”

I want to see the file show up as": USCAL3-IM7208-01.xml

I hope that makes sense.

Thank you,  
-Tim
