# How do i export the ansible output of a playbook TASK to a excel sheet or table?

**URL:** <https://forum.ansible.com/t/how-do-i-export-the-ansible-output-of-a-playbook-task-to-a-excel-sheet-or-table/34783>\
**Category:** Ansible Project\
**Created:** [March 15, 2021, 6:48am UTC](https://forum.ansible.com/t/how-do-i-export-the-ansible-output-of-a-playbook-task-to-a-excel-sheet-or-table/34783 "2021-03-15T06:48:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [March 15, 2021, 6:48am UTC](https://forum.ansible.com/t/how-do-i-export-the-ansible-output-of-a-playbook-task-to-a-excel-sheet-or-table/34783/1 "2021-03-15T06:48:26Z")

</div>

I am writing a script for IOS upgrade in switches and script involves multiple TASKS like checking copying image, settings boot statement, etc. The final task would be to check if IOS upgrade was successful or not and display it on screen.

Mgmt wants only the output message for the final TASK (whether IOS upgrade was succesful or not) to be saved in excel sheet or table. They don’t have the patience to go through the entire output shown by ansible for the playbook.

How do i automatically save the output shown by ansible for only the above mentioned final TASK to a excel sheet/table?

Thanks,

Vikram

---

<div class="post-metadata">

**Author:** ![Pushparaj\_Gothandam](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pushparaj_gothandam/32/5538_2.png) [@Pushparaj\_Gothandam](https://forum.ansible.com/u/Pushparaj_Gothandam)\
**Post date:** [March 15, 2021, 6:59am UTC](https://forum.ansible.com/t/how-do-i-export-the-ansible-output-of-a-playbook-task-to-a-excel-sheet-or-table/34783/2 "2021-03-15T06:59:41Z")

</div>

write a Jinja2 template and render the variable values and get a html table output.

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [March 15, 2021, 7:32am UTC](https://forum.ansible.com/t/how-do-i-export-the-ansible-output-of-a-playbook-task-to-a-excel-sheet-or-table/34783/3 "2021-03-15T07:32:12Z")

</div>

There are multiple ways to do this. Like Pushparaj suggested you can use Jinja2 template and render variables.

Other ways to do this can be -

1. Use JSON callback plugin and convert it CSV file like - [https://stackoverflow.com/questions/54855755/need-to-generate-csv-file-report-out-of-ansible-playbook-output-executed-in-chec](https://stackoverflow.com/questions/54855755/need-to-generate-csv-file-report-out-of-ansible-playbook-output-executed-in-chec)
2. Write your own callback plugin to create a CSV file. You can see [https://docs.ansible.com/ansible/latest/dev\_guide/developing\_plugins.html#callback-plugins](https://docs.ansible.com/ansible/latest/dev_guide/developing_plugins.html#callback-plugins) for callback development. You may want to explore and modify [https://github.com/ansible-collections/ansible.posix/blob/main/plugins/callback/cgroup\_perf\_recap.py](https://github.com/ansible-collections/ansible.posix/blob/main/plugins/callback/cgroup_perf_recap.py) to match your needs.

---

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [March 18, 2021, 7:57am UTC](https://forum.ansible.com/t/how-do-i-export-the-ansible-output-of-a-playbook-task-to-a-excel-sheet-or-table/34783/4 "2021-03-18T07:57:45Z")

</div>

Hi,

I later came to know about lieinfile module and wrote it using that. Thanks for your suggestion though.

- name: GATHER CURRENT VERSION IN DEVICE FACTS  
ios\_facts:

- lineinfile:  
path: ./output/output10.txt  
state: present  
line: - “Image upgrade is successful. Current version is {{ ansible\_net\_version }} for {{ inventory\_hostname }}”  
when: ansible\_net\_version == upgrade\_ios\_version

- lineinfile: path: ./output/output10.txt  
state: present  
line: - “Image upgrade not successful. Current version is {{ ansible\_net\_version }} for {{ inventory\_hostname }}”  
when: ansible\_net\_version != upgrade\_ios\_version

Regards,  
Vikram

---

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [March 18, 2021, 7:58am UTC](https://forum.ansible.com/t/how-do-i-export-the-ansible-output-of-a-playbook-task-to-a-excel-sheet-or-table/34783/5 "2021-03-18T07:58:38Z")

</div>

Hi Pushparaj,

I am aware of writing some basic scripts using Jinja2 template but yet to master it. I later came to know about lieinfile module and wrote it using that

Thanks,  
Vikram
