Bookmark this page

Guided Exercise: Gaining Infrastructure Awareness

Gather device information and generate a dynamic documentation report.

Outcomes

  • Create a playbook that gathers data from Cisco IOS and Arista EOS managed nodes.

  • Use an Ansible Role in a Git repository that creates a dynamic web report to display the data collected by the playbook.

  • Configure the managed nodes and verify that the information is updated in the dynamic web report.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise, and to ensure that all required resources are available. This command also creates a project directory with the files needed for the exercise.

[student@workstation ~]$ lab start network-infra

Instructions

  1. Open the /home/student/network-infra directory in VS Code and review the dynamic_report.yml playbook.

    1. Open VS Code and click FileOpen Folder.

    2. Navigate to Homenetwork-infra and click Open.

      Note

      If prompted, select Trust the authors of all files in the parent folder 'student', and then click Yes, I trust the authors.

    3. Click the dynamic_report.yml playbook. The playbook consists of one play named Play to build a report that uses a role named report. The start script configured the workstation machine as a web server. Because the report is built on this local web server, the play runs on the workstation machine.

      ---
      - name: Play to build a report
        hosts: workstation
        gather_facts: false
        tasks:
          - name: Build the report
            ansible.builtin.include_role:
              name: report
  2. The report role used in the dynamic_report.yml playbook is in the git@git.lab.example.com:student/report Git repository. Create a role requirements file in your project directory and then use the ansible-galaxy command to download and install the report role.

    1. Switch to the Terminal tab in VS Code, or change to the /home/student/network-infra directory in a GNOME terminal:

      [student@workstation ~]$ cd ~/network-infra
      [student@workstation network-infra]$
    2. Use the mkdir command to create the roles directory in your project:

      [student@workstation network-infra]$ mkdir roles
    3. In VS Code, create the roles/requirements.yml file with the following content:

      ---
      - src: git@git.lab.example.com:student/report
        scm: git
        version: main
    4. Use the ansible-galaxy command to download and install the report role into the roles directory of your project:

      [student@workstation network-infra]$ ansible-galaxy install \
      -r roles/requirements.yml -p roles
      Starting galaxy role install process
      - extracting report to /home/student/network-infra/roles/report
      - report (main) was installed successfully
    5. Use the ansible-galaxy command to list the installed roles. Verify that the report role is listed:

      [student@workstation network-infra]$ ansible-galaxy list -p roles
      # /home/student/network-infra/roles
      - report, main
      # /usr/share/ansible/roles
      ...output omitted...
  3. Edit the dynamic_report.yml playbook. Add two plays before the Play to build a report play that gather a full set of facts from the Cisco IOS and Arista EOS managed nodes.

    1. Add the following play as the first play in the dynamic_report.yml playbook to gather all the facts from the ios group of managed nodes. Use the cisco.ios.ios_facts module with the gather_subset parameter in the task of the play:

      ---
      - name: Gather facts from Cisco IOS managed nodes
        hosts: ios
        gather_facts: false
        tasks:
          - name: Gather IOS facts
            cisco.ios.ios_facts:
              gather_subset:
                - all
      
      - name: Play to build a report
        hosts: workstation
        gather_facts: false
        tasks:
          - name: Build the report
            ansible.builtin.include_role:
              name: report
    2. Add another play to the dynamic_report.yml playbook between the two existing plays. This play must gather all the facts from the eos group of managed nodes. Use the arista.eos.eos_facts module with the gather_subset parameter in the task of the play:

      ---
      - name: Gather facts from Cisco IOS managed nodes
        hosts: ios
        gather_facts: false
        tasks:
          - name: Gather IOS facts
            cisco.ios.ios_facts:
              gather_subset:
                - all
      
      - name: Gather facts from Arista EOS managed nodes
        hosts: eos
        gather_facts: false
        tasks:
          - name: Gather EOS facts
            arista.eos.eos_facts:
              gather_subset:
                - all
      
      - name: Play to build a report
        hosts: workstation
        gather_facts: false
        tasks:
          - name: Build the report
            ansible.builtin.include_role:
              name: report
  4. Run the dynamic_report.yml playbook to gather all the facts from the managed nodes and to create the report. You can find the report at http://localhost:8080. The Managed Node column in the generated report shows a set of facts gathered from the managed nodes. Verify the collected data for the arista1.lab.example.com managed nodes.

    1. Use the ansible-navigator command to run the dynamic_report.yml playbook:

      [student@workstation network-infra]$ ansible-navigator run dynamic_report.yml
      
      PLAY [Gather facts from Cisco IOS managed nodes] *********************************
      
      TASK [Gather IOS facts] **********************************************************
      ok: [iosxe2.lab.example.com]
      ok: [iosxe1.lab.example.com]
      
      PLAY [Gather facts from Arista EOS managed nodes] ********************************
      
      TASK [Gather EOS facts] **********************************************************
      ok: [arista2.lab.example.com]
      ok: [arista1.lab.example.com]
      
      PLAY [Play to build a report] ****************************************************
      
      TASK [Build the report] **********************************************************
      
      TASK [report : Copy CSS style] ***************************************************
      changed: [workstation]
      
      TASK [report : Copy CSS images] **************************************************
      changed: [workstation]
      
      TASK [report : Create HTML report] ***********************************************
      changed: [workstation]
      
      PLAY RECAP ***********************************************************************
      arista1.lab.example.com   : ok=1     changed=0     unreachable=0     failed=0 ...
      arista2.lab.example.com   : ok=1     changed=0     unreachable=0     failed=0 ...
      iosxe1.lab.example.com    : ok=1     changed=0     unreachable=0     failed=0 ...
      iosxe2.lab.example.com    : ok=1     changed=0     unreachable=0     failed=0 ...
      workstation               : ok=3     changed=3     unreachable=0     failed=0 ...
    2. Navigate to http://localhost:8080. The report shows relevant information for your network infrastructure.

      Figure 7.2: Example web report
    3. Locate the arista1.lab.example.com managed node. Click Managed Node Information and then click Ansible Automation Information.

      Figure 7.3:

      Gathered facts from the arista1.lab.example.com managed node

      The report shows the collected information from the arista1.lab.example.com managed node.

      Note

      The serial number for your managed node could be different from the one displayed here.

    4. Optional. Click Managed Node Information and Ansible Automation Information for any of the other managed nodes.

  5. The report also displays gathered information related to the configuration of Layer 3 (L3) interfaces, VLANs, and Network Time Protocol (NTP) on the managed nodes.

    Edit the dynamic_report.yml playbook to also gather the subset of resource facts related to L3 and virtual LAN (VLAN) configurations. Use the gather_network_resources parameter with the l3_interfaces and vlans values.

    Run the configure.yml playbook to configure L3, VLANs, and NTP on your managed nodes. When finished, run the dynamic_report.yml playbook again to verify the configured values in the report.

    1. Edit the dynamic_report.yml playbook so that the first two plays gather the L3 and VLAN resources from the managed nodes:

      ---
      - name: Gather facts from Cisco IOS managed nodes
        hosts: ios
        gather_facts: false
        tasks:
          - name: Gather IOS facts
            cisco.ios.ios_facts:
              gather_subset:
                - all
              gather_network_resources:
                - vlans
                - l3_interfaces
      
      - name: Gather facts from Arista EOS managed nodes
        hosts: eos
        gather_facts: false
        tasks:
          - name: Gather EOS facts
            arista.eos.eos_facts:
              gather_subset:
                - all
              gather_network_resources:
                - vlans
                - l3_interfaces
      
      ...output omitted...
    2. Use the ansible-navigator run command to run the configure.yml playbook.

      The configure.yml playbook imports the configure_l3.yml, configure_vlans.yml, and configure_ntp.yml playbooks.

      The configure_l3.yml and the configure_ntp.yml playbooks run against the Cisco IOS and Arista EOS managed nodes. The configure_vlans.yml playbook runs only against the Arista EOS managed nodes.

      [student@workstation network-infra]$ ansible-navigator run configure.yml
      
      ...output omitted...
      
      PLAY RECAP ***********************************************************************
      arista1.lab.example.com   : ok=6     changed=6     unreachable=0     failed=0 ...
      arista2.lab.example.com   : ok=6     changed=6     unreachable=0     failed=0 ...
      iosxe1.lab.example.com    : ok=4     changed=4     unreachable=0     failed=0 ...
      iosxe2.lab.example.com    : ok=4     changed=4     unreachable=0     failed=0 ...

      Note

      The playbooks configure the Cisco IOS and Arista EOS managed nodes based on the variable files in the group_vars directory.

    3. Use the ansible-navigator command to run the dynamic_report.yml playbook again:

      [student@workstation network-infra]$ ansible-navigator run dynamic_report.yml
      
      ...output omitted...
      
      PLAY RECAP ***********************************************************************
      arista1.lab.example.com   : ok=1     changed=0     unreachable=0     failed=0 ...
      arista2.lab.example.com   : ok=1     changed=0     unreachable=0     failed=0 ...
      iosxe1.lab.example.com    : ok=1     changed=0     unreachable=0     failed=0 ...
      iosxe2.lab.example.com    : ok=1     changed=0     unreachable=0     failed=0 ...
      workstation               : ok=3     changed=1     unreachable=0     failed=0 ...
    4. Return to the generated report at http://localhost:8080 and reload the web page. Click L3 interfaces - IP Addresses, VLANs, and NTP for the arista2.lab.example.com and iosxe1.lab.example.com managed nodes.

      Notice the following points:

      • Even though NTP was configured on the managed nodes, the report does not display NTP information because NTP facts were not gathered in the Gather IOS facts and Gather EOS facts tasks in the dynamic_report.yml playbook.

      • Even though VLANs were not configured on the Cisco IOS managed nodes, the report displays VLAN information because VLAN facts were gathered in the Gather IOS facts and Gather EOS facts tasks in the dynamic_report.yml playbook. This results in the report displaying the legacy reserved VLAN information.

      Figure 7.4: L3 interfaces and VLANs facts from the managed nodes
  6. Edit the dynamic_report.yml playbook to also gather the subset of resource facts related to NTP configurations, and then run the dynamic_report.yml playbook again to verify that the NTP configuration is displayed in the report. Use the gather_network_resources parameter with the ntp_global value.

    1. Edit the dynamic_report.yml playbook so that the first two plays also gather the NTP resources from the managed nodes:

      ---
      - name: Gather facts from Cisco IOS managed nodes
        hosts: ios
        gather_facts: false
        tasks:
          - name: Gather IOS facts
            cisco.ios.ios_facts:
              gather_subset:
                - all
              gather_network_resources:
                - vlans
                - l3_interfaces
                - ntp_global
      
      - name: Gather facts from Arista EOS managed nodes
        hosts: eos
        gather_facts: false
        tasks:
          - name: Gather EOS facts
            arista.eos.eos_facts:
              gather_subset:
                - all
              gather_network_resources:
                - vlans
                - l3_interfaces
                - ntp_global
      
      ...output omitted...
    2. Use the ansible-navigator command to run the dynamic_report.yml playbook:

      [student@workstation network-infra]$ ansible-navigator run dynamic_report.yml
      
      ...output omitted...
      
      PLAY RECAP ***********************************************************************
      arista1.lab.example.com   : ok=1     changed=0     unreachable=0     failed=0 ...
      arista2.lab.example.com   : ok=1     changed=0     unreachable=0     failed=0 ...
      iosxe1.lab.example.com    : ok=1     changed=0     unreachable=0     failed=0 ...
      iosxe2.lab.example.com    : ok=1     changed=0     unreachable=0     failed=0 ...
      workstation               : ok=3     changed=1     unreachable=0     failed=0 ...
    3. Return to the generated report at http://localhost:8080 and reload the web page. Click NTP for the arista2.lab.example.com and iosxe1.lab.example.com managed nodes.

      Figure 7.5: NTP configuration on managed nodes

      The report displays the NTP configuration from the managed nodes.

    4. Click NTP again for the arista2.lab.example.com and iosxe1.lab.example.com managed nodes in the report to hide the displayed information.

  7. Close the /home/student/network-infra directory in VS Code. If you are using the GNOME terminal, return to the /home/student directory.

    1. Click FileClose Folder in VS Code to close the /home/student/network-infra directory.

    2. If you are using the GNOME terminal, run the cd command to return to the student home directory:

      [student@workstation network-infra]$ cd

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish network-infra

Revision: do457-2.3-7cfa22a