Red Hat Certified Engineer RHCE · Free Practice Question Medium

Question 14

You are configuring Ansible to use a static inventory for managing a hybrid environment, with some hosts in the cloud and others on-premise. How would you structure the static inventory file to distinguish between cloud and on-premise hosts and apply different variables to each?

  • A

    Structuring Static Inventory for Hybrid Cloud and On-Premise Hosts
    In inventory.ini, group cloud and on-premise hosts:

    This distinguishes between cloud and on-premise hosts and applies specific variables.

  • 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 static inventory.ini file is structured to manage both cloud and on-premise hosts in a hybrid environment by clearly distinguishing between the two types of hosts using groups. The cloud group contains hosts located in the cloud, such as cloud1, with its associated host IP address in AWS. The on_premise group contains on-premise hosts, like host1, with a specified local IP address. Additionally, specific variables are assigned to each group. For example, the cloud group has a variable cloud_type=AWS, indicating it is a cloud-based host in AWS, and the on_premise group has a variable local_network=true, indicating it is part of a local network. By organizing the hosts into groups and applying group-specific variables, this setup ensures that the correct configurations are applied depending on the host's location.

Line-by-Line Explanation

  1. [cloud]

    • Defines the cloud group, which contains hosts located in the cloud. This is the first group of hosts, and any host in this group will have configurations for cloud-specific settings.

  2. cloud1 ansible_host=ec2-52-8-1-2.compute.amazonaws.com

    • Specifies the cloud1 host, which is located in the cloud. The ansible_host variable assigns the IP address or DNS name (ec2-52-8-1-2.compute.amazonaws.com) for this host.

  3. [on_premise]

    • Defines the on_premise group, which contains hosts located on-premises. Any host in this group will have configurations for on-premise-specific settings.

  4. host1 ansible_host=192.168.1.10

    • Specifies the host1 host, which is located on-premises. The ansible_host variable assigns the IP address (192.168.1.10) for this host.

  5. [cloud:vars]

    • This section applies group-specific variables to all hosts in the cloud group.

  6. cloud_type=AWS

    • Defines a variable cloud_type=AWS for all hosts in the cloud group. This variable indicates that the hosts in this group are hosted on AWS.

  7. [on_premise:vars]

    • This section applies group-specific variables to all hosts in the on_premise group.

  8. local_network=true

    • Defines a variable local_network=true for all hosts in the on_premise group. This variable indicates that the hosts are part of a local network.

This configuration in the inventory.ini file ensures that hosts from both cloud and on-premise environments are correctly distinguished using group names, and that each group receives its own specific variables to configure its respective environment correctly. This allows Ansible to manage a hybrid infrastructure effectively, applying appropriate settings based on the host's location.

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