Bookmark this page

Guided Exercise: Managing Network Configuration

In this exercise, you adjust the network configuration of a managed host and collect information about it in a file created by a template.

Outcomes

  • You should be able to configure network settings on managed hosts, and collect network-related Ansible facts.

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

This command prepares your environment and ensures that all required resources are available.

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

Procedure 9.5. Instructions

  1. Review the inventory file in the /home/student/system-network project directory.

    1. Change into the /home/student/system-network directory.

      [student@workstation ~]$ cd ~/system-network
      [student@workstation system-network]$
    2. In the inventory file, verify that servera.lab.example.com is part of the webservers host group. That server has a spare network interface.

      [student@workstation system-network]$ cat inventory
      [webservers]
      servera.lab.example.com
  2. Install the redhat.rhel_system_roles Ansible Content Collection from the redhat-rhel_system_roles-1.19.3.tar.gz file to the collections directory in the project directory.

    1. Use the ansible-galaxy command to install the rhel_system_roles Ansible Content Collection from the redhat-rhel_system_roles-1.19.3.tar.gz file into the project's collections directory.

      [student@workstation system-network]$ ansible-galaxy collection install \
      > ./redhat-rhel_system_roles-1.19.3.tar.gz -p collections
      Starting galaxy collection install process
      Process install dependency map
      Starting collection install process
      Installing 'redhat.rhel_system_roles:1.19.3' to '/home/student/system-network/collections/ansible_collections/redhat/rhel_system_roles'
      redhat.rhel_system_roles:1.19.3 was installed successfully
  3. Create a playbook that uses the redhat.rhel_system_roles.network role to configure the network interface eth1 on servera.lab.example.com with the 172.25.250.30/24 IP address and network prefix.

    1. Create a playbook named playbook.yml, and add one play that targets the webservers host group. Include the rhel_system_roles.network role in the roles section of the play.

      ---
      - name: NIC Configuration
        hosts: webservers
      
        roles:
          - redhat.rhel_system_roles.network
    2. The documentation for the redhat.rhel_system_roles.network system role lists the variables and options that are available to configure its operation.

      Run ansible-navigator collections, select the redhat.rhel_system_roles collection, and then select the network role to see its documentation.

      Review the Setting the IP configuration: section (near line 1219 of the documentation) and determine which variable is required to configure the eth1 network interface with a static IP address and network prefix.

      For your convenience, that part of the documentation reads as follows:

      ...output omitted...
      
      Setting the IP configuration:
      
      ```yaml
      network_connections:
        - name: eth0
          type: ethernet
          ip:
            route_metric4: 100
            dhcp4: no
            #dhcp4_send_hostname: no
            gateway4: 192.0.2.1
      
            dns:
              - 192.0.2.2
              - 198.51.100.5
            dns_search:
              - example.com
              - subdomain.example.com
            dns_options:
              - rotate
              - timeout:1
      
            route_metric6: -1
            auto6: no
            gateway6: 2001:db8::1
      
            address:
              - 192.0.2.3/24
              - 198.51.100.3/26
              - 2001:db8::80/7
      
      ...output omitted...
    3. Create the group_vars/webservers subdirectory.

      [student@workstation system-network]$ mkdir -pv group_vars/webservers
      mkdir: created directory 'group_vars'
      mkdir: created directory 'group_vars/webservers'
    4. Create a new variable file named network.yml in the group_vars/webservers directory to define the network_connections role variable for the webservers group.

      The value of that variable must configure a network connection for the eth1 network interface that assigns it the static IP address and network prefix 172.25.250.30/24.

      When completed, the file contains the following content:

      [student@workstation system-network]$ cat group_vars/webservers/network.yml
      ---
      network_connections:
        - name: eth1
          type: ethernet
          ip:
            address:
              - 172.25.250.30/24
    5. Run the playbook to configure the secondary network interface on servera.

      [student@workstation system-network]$ ansible-navigator run \
      > -m stdout playbook.yml
      
      PLAY [NIC Configuration] *******************************************************
      
      TASK [Gathering Facts] *********************************************************
      ok: [servera.lab.example.com]
      
      TASK [redhat.rhel_system_roles.network : Ensure ansible_facts used by role] ****
      included: /home/student/system-network/collections/ansible_collections/redhat/rhel_system_roles/roles/network/tasks/set_facts.yml for servera.lab.example.com
      
      TASK [redhat.rhel_system_roles.network : Ensure ansible_facts used by role are present] ***
      ok: [servera.lab.example.com]
      
      TASK [redhat.rhel_system_roles.network : Check which services are running] *****
      ok: [servera.lab.example.com]
      
      TASK [redhat.rhel_system_roles.network : Check which packages are installed] ***
      ok: [servera.lab.example.com]
      
      TASK [redhat.rhel_system_roles.network : Print network provider] ***************
      ok: [servera.lab.example.com] => {
          "msg": "Using network provider: nm"
      }
      
      TASK [redhat.rhel_system_roles.network : Abort applying the network state configuration if using the network_state variable with the initscripts provider] ***
      skipping: [servera.lab.example.com]
      
      ...output omitted...
      
      TASK [redhat.rhel_system_roles.network : Configure networking connection profiles] ***
      changed: [servera.lab.example.com]
      
      TASK [redhat.rhel_system_roles.network : Configure networking state] ***********
      skipping: [servera.lab.example.com]
      
      TASK [redhat.rhel_system_roles.network : Show stderr messages for the network_connections] ***
      ok: [servera.lab.example.com] => {
          "__network_connections_result.stderr_lines": [
              "[002] <info>  #0, state:None persistent_state:present, 'eth1': add connection eth1, c0177289-f461-4042-b9d4-86fd1b235be1"
          ]
      }
      
      TASK [redhat.rhel_system_roles.network : Show debug messages for the network_connections] ***
      skipping: [servera.lab.example.com]
      
      TASK [redhat.rhel_system_roles.network : Show debug messages for the network_state] ***
      skipping: [servera.lab.example.com]
      
      TASK [redhat.rhel_system_roles.network : Re-test connectivity] *****************
      ok: [servera.lab.example.com]
      
      PLAY RECAP *********************************************************************
      servera.lab.example.com    : ok=10   changed=1    unreachable=0    failed=0    skipped=12   rescued=0    ignored=0
  4. Run the get-eth1.yml playbook provided in the project directory to verify that the eth1 network interface configuration on servera is correct.

    Verify that the eth1 network interface uses the 172.25.250.30 IP address with the /24 network prefix (equivalent to the 255.255.255.0 subnet mask). It might take up to a minute to configure the IP address.

    [student@workstation system-network]$ ansible-navigator run \
    > -m stdout get-eth1.yml
    
    PLAY [Obtain network info for webservers] **************************************
    
    TASK [Gathering Facts] *********************************************************
    ok: [servera.lab.example.com]
    
    TASK [Display eth1 info] *******************************************************
    ok: [servera.lab.example.com] => {
        "ansible_facts['eth1']['ipv4']": {
            "address": "172.25.250.30",
            "broadcast": "172.25.250.255",
            "netmask": "255.255.255.0",
            "network": "172.25.250.0",
            "prefix": "24"
        }
    }
    
    PLAY RECAP *********************************************************************
    servera.lab.example.com    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Finish

On the workstation machine, change to the student user home directory and 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 system-network

This concludes the section.

Revision: rh294-9.0-c95c7de