Bookmark this page

Guided Exercise: Configuring Device Login Banners

Write and run an Ansible Playbook.

Outcomes

  • Create and run a playbook to configure the login banners on Cisco devices running the IOS XE operating system.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command ensures that:

  • Directories are created for this exercise.

  • The podman, ansible-core, and ansible-navigator packages are installed.

  • An ansible.cfg file and an ansible-navigator.yml file are created for this exercise.

  • An inventory file is created for this exercise.

[student@workstation ~]$ lab start implement-playbooks

Instructions

  1. Open Visual Studio Code (VS Code) on the workstation machine and open the ~/implement-playbooks directory.

    1. Click Activities on the workstation top bar, enter code in the Type to search field, and then press Enter.

    2. In VS Code, click FileOpen Folder. Click Homeimplement-playbooks and then click Open.

      Note

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

  2. Use VS Code on the workstation machine to create a playbook named banner.yml. Add a task to the playbook that configures the login banners for managed nodes in the ios inventory group.

    1. In VS Code, click FileNew Text File.

    2. Click Select a language and then click Ansible (ansible).

    3. Create a playbook with the following contents, and save the file as banner.yml.

      ---
      - name: Configure login banners
        hosts: ios
        gather_facts: false
        tasks:
          - name: Configure banner on IOS devices
            cisco.ios.ios_banner:
              banner: login
              text: Managed by Ansible
              state: present
            notify: ios_save_changes
      
        handlers:
          - name: ios_save_changes
            cisco.ios.ios_config:
              save_when: always
  3. Open a terminal, change to the ~/implement-playbooks directory, and use the ansible-navigator command to run the banner.yml playbook.

    [student@workstation ~] cd ~/implement-playbooks
    [student@workstation implement-playbooks]$ ansible-navigator run banner.yml \
    -m stdout
    
    PLAY [Configure login banners] *************************************************
    
    TASK [Configure banner on IOS devices] *****************************************
    changed: [iosxe1.lab.example.com]
    changed: [iosxe2.lab.example.com]
    
    RUNNING HANDLER [ios_save_changes] *********************************************
    changed: [iosxe1.lab.example.com]
    changed: [iosxe2.lab.example.com]
    
    PLAY RECAP *********************************************************************
    iosxe1.lab.example.com     : ok=2    changed=2    unreachable=0    failed=0  ...
    iosxe2.lab.example.com     : ok=2    changed=2    unreachable=0    failed=0  ...
  4. Verify that the login banner was correctly configured on the iosxe1.lab.example.com and iosxe2.lab.example.com managed nodes, and then change back to the /home/student directory.

    1. Connect to the iosxe1.lab.example.com managed node by using SSH and verify the login banner. Then log out from the iosxe1.lab.example.com managed node.

      [student@workstation implement-playbooks]$ ssh iosxe1.lab.example.com
      
      Managed by Ansible
      
      
      
      iosxe1.lab.example.com#exit
      Connection to iosxe1.lab.example.com closed by remote host.
      Connection to iosxe1.lab.example.com closed.
    2. Connect to the iosxe2.lab.example.com managed node by using SSH and verify the login banner. Then log out from the iosxe2.lab.example.com managed node.

      [student@workstation implement-playbooks]$ ssh iosxe2.lab.example.com
      
      Managed by Ansible
      
      
      
      iosxe2.lab.example.com#exit
      Connection to iosxe2.lab.example.com closed by remote host.
      Connection to iosxe2.lab.example.com closed.
  5. Close the /home/student/implement-playbooks 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/implement-playbooks directory.

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

      [student@workstation implement-playbooks]$ cd
      [student@workstation ~]$

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 implement-playbooks

Revision: do457-2.3-7cfa22a