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

    picture of debug tasks
  • Working with Ansible facts

    display vlans picture
  • Running the Ansible Playbook

    display vlans picture

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.yml playbook:

        - 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 stdout
    Using 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 :doc command 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.facts module gathers structured data specific for Cisco IOS. There are relevant modules for each network platform. For example there is a junipernetworks.junos.facts for Juniper Junos, and a arista.eos.facts for Arista EOS.

  • The debug module allows an Ansible Playbook to print values to the terminal window.