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
Ininventory.ini, group cloud and on-premise hosts:- [cloud]
- cloud1 ansible_host=ec2-52-0-1-2.compute.amazonaws.com
- [on_premise]
- host1 ansible_host=192.168.1.10
- [cloud:vars]
- cloud_type=AWS
- [on_premise:vars]
- local_network=true
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
[cloud]Defines the
cloudgroup, 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.
cloud1 ansible_host=ec2-52-8-1-2.compute.amazonaws.comSpecifies the
cloud1host, which is located in the cloud. Theansible_hostvariable assigns the IP address or DNS name (ec2-52-8-1-2.compute.amazonaws.com) for this host.
[on_premise]Defines the
on_premisegroup, which contains hosts located on-premises. Any host in this group will have configurations for on-premise-specific settings.
host1 ansible_host=192.168.1.10Specifies the
host1host, which is located on-premises. Theansible_hostvariable assigns the IP address (192.168.1.10) for this host.
[cloud:vars]This section applies group-specific variables to all hosts in the
cloudgroup.
cloud_type=AWSDefines a variable
cloud_type=AWSfor all hosts in thecloudgroup. This variable indicates that the hosts in this group are hosted on AWS.
[on_premise:vars]This section applies group-specific variables to all hosts in the
on_premisegroup.
local_network=trueDefines a variable
local_network=truefor all hosts in theon_premisegroup. 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.
