Red Hat Certified Engineer RHCE · Free Practice Question Medium

Question 19

A Content Collection you’re using includes roles for configuring network devices. How would you ensure that the roles are applied to specific network devices based on their inventory group (e.g., routers, switches) in your playbook?

  • A

    Applying Roles to Specific Network Devices Based on Inventory Groups
    In your inventory.ini:

    In the playbook, apply roles based on the group:

    This ensures roles are applied based on the device type.

  • B

    This is a performance based question and not multiple choice.  Therefore the answer is in #1.  If you require additional explanation, please ask your question in the Q&A section.

Reveal correct answer

Correct answer: A

A.

In this solution, the Ansible playbook is structured to apply specific roles to different network devices based on their inventory group. In the inventory.ini file, network devices are grouped into [routers] and [switches] groups. Each device in these groups is associated with a specific role. In the playbook, the routers group will apply the configure_router_role, while the switches group will apply the configure_switch_role. This ensures that the correct configuration role is applied to each device type (router or switch) based on the group it belongs to in the inventory, allowing for efficient management of network devices.

Line-by-Line Explanation

  1. [routers]

    • Defines the routers group in the inventory. This group will include all the routers that need to be configured.

  2. router1 ansible_host=192.168.1.1

    • Specifies that router1 is part of the routers group, and it has the IP address 192.168.1.1. Ansible will use this IP to connect to the router.

  3. [switches]

    • Defines the switches group in the inventory. This group will include all the switches that need to be configured.

  4. switch1 ansible_host=192.168.1.2

    • Specifies that switch1 is part of the switches group, and it has the IP address 192.168.1.2. Ansible will use this IP to connect to the switch.

  5. - hosts: routers

    • In the playbook, this line indicates that the following task will be executed on all hosts in the routers group.

  6. roles:

    • Introduces the list of roles to be applied to the hosts in the routers group.

  7. - configure_router_role

    • Specifies the role to be applied to the devices in the routers group. In this case, it is the configure_router_role, which contains tasks for configuring routers.

  8. - hosts: switches

    • In the playbook, this line indicates that the following task will be executed on all hosts in the switches group.

  9. roles:

    • Introduces the list of roles to be applied to the hosts in the switches group.

  10. - configure_switch_role

    • Specifies the role to be applied to the devices in the switches group. In this case, it is the configure_switch_role, which contains tasks for configuring switches.

This method ensures that the correct role is applied to each device type (router or switch), based on the inventory group the device belongs to. It makes managing different network devices efficient by applying group-specific roles for configuration.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need