Bookmark this page

Guided Exercise: Managing Network Configuration

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

Outcomes

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

Run the lab system-network start script from workstation to configure the environment for the exercise. The script creates the system-network working directory, and downloads the Ansible configuration file and the host inventory file needed for the exercise.

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

Procedure 9.5. Instructions

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

    1. As the student user on workstation, change to the /home/student/system-network working directory.

      [student@workstation ~]$ cd ~/system-network
      [student@workstation system-network]$
    2. Verify that servera.lab.example.com is part of the webservers host group. This server has a spare network interface.

      [student@workstation system-network]$ cat inventory
      [webservers]
      servera.lab.example.com
  2. Use the ansible-galaxy command to verify that system roles are available. If no roles are available, you need to install the rhel-system-roles package.

    [student@workstation system-network]$ ansible-galaxy list
    # /usr/share/ansible/roles
    - linux-system-roles.kdump, (unknown version)
    - linux-system-roles.network, (unknown version)
    - linux-system-roles.postfix, (unknown version)
    - linux-system-roles.selinux, (unknown version)
    - linux-system-roles.timesync, (unknown version)
    - rhel-system-roles.kdump, (unknown version)
    - rhel-system-roles.network, (unknown version)
    - rhel-system-roles.postfix, (unknown version)
    - rhel-system-roles.selinux, (unknown version)
    - rhel-system-roles.timesync, (unknown version)
    # /etc/ansible/roles
     [WARNING]: - the configured path /home/student/.ansible/roles does not exist.
  3. Create a playbook which uses the linux-system-roles.network role to configure the spare network interface eth1 on servera.lab.example.com with the 172.25.250.30 IP address.

    1. Create a playbook, playbook.yml, with 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:
          - rhel-system-roles.network
    2. Review the Role Variables section of the README.md file for the rhel-system-roles.network role. Determine the role variables to configure the eth1 network interface with the 172.25.250.30 IP address.

      [student@workstation system-network]$ cat \
      > /usr/share/doc/rhel-system-roles/network/README.md
      ...output omitted...
      Setting the IP configuration:
      ...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 file network.yml to define role variables. Because these variable values apply to the hosts on the webservers host group, you need to create that file in the group_vars/webservers directory. Add variable definitions to support the configuration of the eth1 network interface. The file now contains:

      ---
      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-playbook playbook.yml
      
      PLAY [NIC Configuration] *******************************************************
      
      TASK [Gathering Facts] *********************************************************
      ok: [servera.lab.example.com]
      
      TASK [rhel-system-roles.network : Check which services are running] ************
      ok: [servera.lab.example.com]
      
      TASK [rhel-system-roles.network : Check which packages are installed] **********
      ok: [servera.lab.example.com]
      
      TASK [rhel-system-roles.network : Print network provider] **********************
      ok: [servera.lab.example.com] => {
          "msg": "Using network provider: nm"
      }
      
      TASK [rhel-system-roles.network : Install packages] ****************************
      skipping: [servera.lab.example.com]
      
      TASK [rhel-system-roles.network : Enable network service] **********************
      ok: [servera.lab.example.com]
      
      TASK [rhel-system-roles.network : Configure networking connection profiles] ****
      ...output omitted...
      
      changed: [servera.lab.example.com]
      
      TASK [rhel-system-roles.network : Re-test connectivity] ************************
      ok: [servera.lab.example.com]
      
      PLAY RECAP *********************************************************************
      servera.lab.example.com    : ok=7    changed=1    unreachable=0    failed=0
      skipped=1    rescued=0    ignored=0
  4. Use the Ansible setup module on an Ansible adhoc command to verify that the eth1 network interface configuration on servera is correct.

    1. Use the setup Ansible module to list all the Ansible facts available for servera. Filter results for the eth1 network interface with the -a 'filter=filter_string' option. Verify that the eth1 network interface uses the 172.25.250.30 IP address. It may take up to a minute to configure the IP address.

      [student@workstation system-network]$ ansible webservers -m setup \
      > -a 'filter=ansible_eth1'
      servera.lab.example.com | SUCCESS => {
          "ansible_facts": {
              "ansible_eth1": {
      ...output omitted...
                  "ipv4": {
                      "address": "172.25.250.30",
                      "broadcast": "172.25.250.255",
                      "netmask": "255.255.255.0",
                      "network": "172.25.250.0"
                  },
      ...output omitted...

Finish

On workstation, run the lab system-network finish script to clean up the resources created in this exercise.

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

This concludes the guided exercise.

Revision: rh294-8.4-9cb53f0