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

2,338 views
Skip to first unread message

Vikram S

unread,
Mar 15, 2021, 2:48:26 AM3/15/21
to Ansible Project

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

Rajthecomputerguy

unread,
Mar 15, 2021, 3:00:38 AM3/15/21
to ansible...@googlegroups.com
write a Jinja2 template and render the variable values and get a html table output. 

--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/cc7108fc-9342-4ffc-87a5-04cc01e2c15cn%40googlegroups.com.


--

Thanks,

Pushparaj G


Abhijeet Kasurde

unread,
Mar 15, 2021, 3:32:42 AM3/15/21
to ansible...@googlegroups.com
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 -

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 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 to match your needs.





--
Thanks,
Abhijeet Kasurde

Vikram S

unread,
Mar 18, 2021, 3:57:45 AM3/18/21
to Ansible Project
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

Vikram S

unread,
Mar 18, 2021, 3:58:38 AM3/18/21
to Ansible Project
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

Reply all
Reply to author
Forward
0 new messages