Using the Debug Module
Learn how to use facts with the debug module
Displaying output - The "debug" module
-
The debug module is used like a "print" statement in most programming languages. Variables are accessed using "{{ }}" - quoted curly braces
-
Working with Ansible facts
-
Running the Ansible Playbook
Lets get started
That is the end of of your lab briefing!
Step 1 - Using the debug task
We will add two additional tasks that display the routers' OS version and serial number.
-
Click on the code-server tab and append the following tasks to your
facts.ymlplaybook:- name: display version debug: msg: "The IOS version is: {{ ansible_net_version }}" - name: display serial number debug: msg: "The serial number is: {{ ansible_net_serialnum }}"
Step 2 - Running the playbook with stdout
-
Click on the terminal tab. Now re-run the playbook using the ansible-navigator and the --mode stdout.
ansible-navigator run facts.yml --mode stdoutUsing less than 20 lines of "code" you have just automated version and serial number collection. Imagine if you were running this against your production network! You have actionable data in hand that does not go out of date.
Takeaways
-
The
ansible-navigator :doccommand will allow you access to documentation without an internet connection. This documentation also matches the version of Ansible on the control node. -
The
cisco.ios.factsmodule gathers structured data specific for Cisco IOS. There are relevant modules for each network platform. For example there is ajunipernetworks.junos.factsfor Juniper Junos, and aarista.eos.factsfor Arista EOS. -
The
debugmodule allows an Ansible Playbook to print values to the terminal window.