# Import excel file values to ansible

**URL:** <https://forum.ansible.com/t/import-excel-file-values-to-ansible/24261>\
**Category:** Ansible Project\
**Created:** [April 20, 2017, 8:31am UTC](https://forum.ansible.com/t/import-excel-file-values-to-ansible/24261 "2017-04-20T08:31:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![groupfiles14](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@groupfiles14](https://forum.ansible.com/u/groupfiles14)\
**Post date:** [April 20, 2017, 8:31am UTC](https://forum.ansible.com/t/import-excel-file-values-to-ansible/24261/1 "2017-04-20T08:31:17Z")

</div>

i have an excel file with 2 columns and multiple rows of data, , basically like a key value pair, i want to import those as it is into win\_Regedit for creating registry entries, how can i do it? i want the column1 row1 to be the name in win\_regedit and column2 row1 to be the data in win\_regedit

---

<div class="post-metadata">

**Author:** ![groupfiles14](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@groupfiles14](https://forum.ansible.com/u/groupfiles14)\
**Post date:** [April 21, 2017, 4:59am UTC](https://forum.ansible.com/t/import-excel-file-values-to-ansible/24261/2 "2017-04-21T04:59:32Z")

</div>

any help?

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [April 21, 2017, 5:25am UTC](https://forum.ansible.com/t/import-excel-file-values-to-ansible/24261/3 "2017-04-21T05:25:01Z")

</div>

You are probably best off using a flat text file for this as Ansible can’t natively parse Excel files. A very basic (can’t guarantee to work) example of using JSON for this would be

JSON File:

[  
{  
“path”: “HKLM:\Software\MyCompany”,  
“name”: “hello”,  
“data”: “world”  
},  
{

“path”: “HKLM:\Software\MyCompany”,  
“name”: “hi”,  
“data”: “ansible”

}  
]

Ansible Tasks:

# If the JSON file is on your Windows box

- name: read remote file  
slurp:  
src: C:\json\_file.txt  
register: reg\_changes\_raw

- name: convert raw slurp to json object  
set\_fact:  
reg\_changed: “{{ reg\_changes\_raw | b64decode | from\_json }}”

# If the JSON file in on your Ansible host

- name: read local file  
set\_fact:  
reg\_changes: “{{ lookup(file, ‘json\_file.json’) | from\_json }}”

# Loop through JSON for win\_regedit

- name: win\_regedit tasks  
win\_regedit:  
path: “{{item.path}}”  
name: “{{item.name}}”  
data: “{{item.data}}”  
with\_items: “{{reg\_changes}}”

How you implement this is up to you but if it is the same reg keys you need to update and it changes only sporadically you should probably just stick with using the group\_vars instead of dealing with external files

---

<div class="post-metadata">

**Author:** ![groupfiles14](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@groupfiles14](https://forum.ansible.com/u/groupfiles14)\
**Post date:** [April 21, 2017, 8:20am UTC](https://forum.ansible.com/t/import-excel-file-values-to-ansible/24261/4 "2017-04-21T08:20:37Z")

</div>

Thanks for the reply

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 21, 2017, 8:04pm UTC](https://forum.ansible.com/t/import-excel-file-values-to-ansible/24261/5 "2017-04-21T20:04:26Z")

</div>

Ansible has a 'csv' lookup plugin that can read the data, so somthing like:

- lineinfile: ...  
&nbsp;&nbsp;with\_csvfile: '/path/to/excel.csv' ...

---

<div class="post-metadata">

**Author:** ![groupfiles14](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@groupfiles14](https://forum.ansible.com/u/groupfiles14)\
**Post date:** [April 23, 2017, 8:12am UTC](https://forum.ansible.com/t/import-excel-file-values-to-ansible/24261/6 "2017-04-23T08:12:07Z")

</div>

can you post an example to read csv file, and also when i have a compressed json ansible is not able to read it, can i decompress the json to make it work?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 24, 2017, 7:40pm UTC](https://forum.ansible.com/t/import-excel-file-values-to-ansible/24261/7 "2017-04-24T19:40:56Z")

</div>

For an example [http://docs.ansible.com/ansible/playbooks\_lookups.html#the-csv-file-lookup](http://docs.ansible.com/ansible/playbooks_lookups.html#the-csv-file-lookup)

The include\_vars/vars\_file will read JSON (as it is a subset of YAML),  
Ansible does not support compressed files directly.

---

<div class="post-metadata">

**Author:** ![SUMIT\_SAHAY](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@SUMIT\_SAHAY](https://forum.ansible.com/u/SUMIT_SAHAY)\
**Post date:** [May 10, 2018, 7:24am UTC](https://forum.ansible.com/t/import-excel-file-values-to-ansible/24261/8 "2018-05-10T07:24:35Z")

</div>

Hi Brian,

I want to read the content of the file using ansible playbook, is there a way to do this.

If something is there kindly share the solution.

Regards  
Sumit Sahay
