Exercise 1.0: Exploring the lab environment

Before you get started, please join us on slack! Click here to join the ansiblenetwork slack. This will allow you to chat with other network automation engineers and get help after the workshops concludes.

Objective

Explore and understand the lab environment.

These first few lab exercises will be exploring the command-line utilities of the Ansible Automation Platform. This includes

  • ansible-navigator - a command line utility and text-based user interface (TUI) for running and developing Ansible automation content.

  • ansible-core - the base executable that provides the framework, language and functions that underpin the Ansible Automation Platform. It also includes various cli tools like ansible, ansible-playbook and ansible-doc. Ansible Core acts as the bridge between the upstream community with the free and open source Ansible and connects it to the downstream enterprise automation offering from Red Hat, the Ansible Automation Platform.

  • Execution Environments - not specifically covered in this workshop because the built-in Ansible Execution Environments already included all the Red Hat supported collections which includes all the network collections we use for this workshop. Execution Environments are container images that can be utilized as Ansible execution.

  • ansible-builder - not specifically covered in this workshop, ansible-builder is a command line utility to automate the process of building Execution Environments.

If you need more information on new Ansible Automation Platform components bookmark this landing page https://red.ht/AAP-20

Note

Before you get started, please join us on slack! Click here to join the ansiblenetwork slack. This will allow you to chat with other network automation engineers and get help after the workshops concludes. If the link goes stale please email Ansible Technical Marketing

Guide

Step 1 - Connecting via VS Code

Note

It is highly encouraged to use Visual Studio Code to complete the workshop exercises. Visual Studio Code provides:

  • A file browser

  • A text editor with syntax highlighting

  • A in-browser terminal


Direct SSH access is available as a backup, or if Visual Studio Code is not sufficient to the student. There is a short YouTube video provided if you need additional clarity: Ansible Workshops - Accessing your workbench environment.


  • Connect to Visual Studio Code from the F5 UDF components page . The password is provided below the WebUI link.

    launch page

  • Type in the provided password to connect.

    login vs code

  • Open the User Directory directory in Visual Studio Code, (File –> Open Folder –> Ensure that the user rhel-user is selected or part of the path and then Click OK).

    picture of file browser

  • This would be /home/rhel-user once connected it will give a Trust Warning Check the box and click Yes, I trust the authors

    trust connection

  • From here on the left pane you can click on the individual exercise folders and then click on the yaml files to check the content of the files.


Step 2 - Using the Terminal

  • Open a terminal in Visual Studio Code (Terminal –> New Terminal)

    picture of new terminal

  • Navigate to the f5-bd-ansible-labs and the 101-F5-Basics directories on the Ansible control node terminal and run the pwd command to verify you are in the correct directory

    cd ~/f5-bd-ansible-labs/101-F5-Basics/
    
    pwd
    

The Output should look something like

[rhel-user@ede... ~]$ ~/f5-bd-ansible-labs/101-F5-Basics/
[rhel-user@ede... 101-F5-Basics]$ pwd
/home/rhel-user/f5-bd-ansible-labs/101-F5-Basics
[rhel-user@ede... 101-F5-Basics]$
  • ~ - the tilde in this context is a shortcut for the home directory, i.e. /home/student1

  • cd - Linux command to change directory

  • pwd - Linux command for print working directory. This will show the full path to the current working directory.


Step 3 - Examining Execution Environments

  • Run the ansible-navigator command with the images argument to look at execution environments configured on the control node:

    ansible-navigator images
    
    ansible-navigator images

    Note: The output you see might differ from the above output

  • This command gives you information about all currently installed Execution Environments or EEs for short. Investigate an EE by pressing the corresponding number.

    ee main menu
  • Selecting 2 for Ansible version and collections will show us all Ansible Collections installed on that particular EE, and the version of ansible-core:

    ee info
  • When completed keep pressing ESC many times or type :quit to quit out of the ansible-navigator menus


Step 4 - Examining the ansible-navigator configuration

  • Either use Visual Studio Code to open or use the cat command to view the contents of the ansible-navigator.yml file. The file is located in the home directory:

    cat ~/.ansible-navigator.yml
    

    Output should look something like

    ---
    ansible-navigator:
    ansible:
       inventory:
          entries:
          - /home/rhel-user/lab_inventory/hosts
    execution-environment:
       container-engine: podman
       enabled: true
       image: quay.io/f5_business_development/f5_ee:latest
       #image: quay.io/f5_business_development/f5_ee_static_build:latest  # This is a backup image with a static build of collections known to work
       pull:
          policy: missing
       volume-mounts:
       - dest: /tmp/f5/
          src: /f5/code-output/
       - dest: /usr/share/nginx/html/asm-profiles
          src: /usr/share/nginx/html/asm-profiles
    

  • Note the following parameters within the ansible-navigator.yml file:

    • inventories: shows the location of the ansible inventory being used

    • execution-environment: where the default execution environment is set

    • volume-mounts: where local system folders are being passed through to the cotainer envrionemnt to migrate items outside of the container.

    For a full listing of every configurable knob checkout the documentation


Step 5 - Examining inventory

The scope of a play within a playbook is limited to the groups of hosts declared within an Ansible inventory. Ansible supports multiple inventory types. An inventory could be a simple flat file with a collection of hosts defined within it or it could be a dynamic script (potentially querying a CMDB backend) that generates a list of devices to run the playbook against.

In this lab you will work with a file based inventory written in the ini format. Either use Visual Studio Code to open or use the cat command to view the contents of the ~/lab_inventory/hosts file.

cat ~/lab_inventory/hosts
[all:vars]
ansible_user=rhel-user
ansible_password=Ansible123!
ansible_port=22
ansible_become_pass="{{ ansible_password }}"
lab_version="udf"
ansible_python_interpreter=/usr/bin/python3

[lb]
f5 ansible_host=10.1.1.7 ansible_user=admin private_ip=10.1.20.30 ansible_password=Ansible123! server_port=443

[control]
ansible ansible_host=10.1.1.4 ansible_user=rhel-user private_ip=10.1.1.4

[web]
node1 ansible_host=10.1.1.5 ansible_user=rhel-user private_ip=10.1.10.5
node2 ansible_host=10.1.1.6 ansible_user=rhel-user private_ip=10.1.10.6

Step 6 - Understanding inventory

In the above output every [ ] defines a group. For example [web] is a group that contains the hosts node1 and node2.

Note: A group called all always exists and contains all groups and hosts defined within an inventory.

We can associate variables to groups and hosts. Host variables are declared/defined on the same line as the host themselves. For example for the host f5:

f5 ansible_host=34.199.128.69 ansible_user=admin private_ip=172.16.26.136 ansible_password=admin

  • f5 - The name that Ansible will use. This can but does not have to rely on DNS

  • ansible_host - The IP address that ansible will use, if not configured it will default to DNS

  • ansible_user - The user ansible will use to login to this host, if not configured it will default to the user the playbook is run from

  • private_ip - This value is not reserved by ansible so it will default to a host variable. This variable can be used by playbooks or ignored completely.

  • ansible_password - The password ansible will use to login to this host, if not configured it will assume the user the playbook ran from has access to this host through SSH keys.

Does the password have to be in plain text? No, Red Hat Ansible Tower can take care of credential management in an easy to use web GUI or a user may use ansible-vault


Step 7 - Using ansible-navigator to explore inventory

We can also use the ansible-navigator TUI to explore inventory.

  • Run the ansible-navigator inventory command to bring up inventory in the TUI:

    ansible-navigator inventory
    
    ansible-navigator tui

    ansible-navigator tui

  • Pressing 0 or 1 on your keyboard will open groups or hosts respectively.

    ansible-navigator groups

    ansible-navigator groups

  • Press the Esc key to go up a level, or press corisponding number to zoom in to a host (within a group or within hosts):

    ansible-navigator host

    ansible-navigator host

  • Quit the TUI using the :quit command or continue pressing ESC


Complete

You have completed lab exercise 1!

You now understand:

  • How to connect to the lab environment with Visual Studio Code

  • How to explore execution environments with ansible-navigator

  • Where the Ansible Navigator Configuration (ansible-navigator.yml) is located

  • Where the inventory is stored for command-line exercises

  • How to use ansible-navigator TUI (Text-based user interface)