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?
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
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