All exams← All Red Hat Certified Engineer (RHCE) exam (EX294) notes

Ansible Core Components: Red Hat Certified Engineer (RHCE) exam (EX294) revision notes

Revision notes

Ansible is an open-source automation engine that automates software provisioning, configuration management, and application deployment. It is agentless, meaning no special software needs to be installed on the managed nodes, relying primarily on SSH for communication and Python for module execution.

## Control Node & Managed Nodes

The Control Node is the machine where Ansible is installed and executed. It's where you run `ansible` commands or `ansible-playbook`. Managed Nodes (also called hosts) are the target servers or devices that Ansible manages. Communication between the control node and managed nodes typically occurs over SSH.

## Inventory

The Inventory is a file (or set of files) that defines the managed nodes Ansible will operate on. It lists hosts, groups them, and can assign variables specific to hosts or groups. Inventories can be static (INI or YAML files) or dynamic (generated by scripts).

  • INI format: `[webservers]` `host1.example.com`
  • YAML format: `all:` ` hosts:` ` host1.example.com:`

You can use the `ansible-inventory` command to view and manage your inventory.

## Modules & Tasks

Modules are the actual units of code Ansible executes on managed nodes. Each module is designed to perform a specific action, such as installing a package, managing a service, or copying a file. Modules are generally idempotent, meaning they can be run multiple times without causing unintended changes beyond the initial execution.

A Task is a call to an Ansible module with specific arguments. Tasks are defined within plays in a playbook.

  • Example Task: `- name: Ensure httpd is installed` ` ansible.builtin.yum: name=httpd state=present`

## Playbooks & Plays

Playbooks are YAML formatted files that are the core of Ansible's configuration, deployment, and orchestration language. They contain one or more Plays.

A Play is a block within a playbook that maps a set of tasks to a specific group of hosts defined in the inventory. Each play targets a specific set of hosts and runs tasks on them.

  • Playbook structure:

```yaml

---

  • name: Configure web servers

hosts: webservers

tasks:

  • name: Install Nginx

ansible.builtin.dnf:

name: nginx

state: present

```

## Variables & Facts

Variables are used to store values that can be reused throughout playbooks, making them more dynamic and flexible. They can be defined in inventory, playbooks, or separate variable files.

Facts are pieces of information about managed nodes (e.g., operating system, IP addresses, memory) that Ansible gathers automatically using the `setup` module. These facts can be accessed as variables within playbooks and are useful for conditional logic or dynamic configuration.

## Plugins

Plugins extend Ansible's core functionality. Examples include: Connection plugins (how Ansible connects), Lookup plugins (fetch external data), Filter plugins (manipulate data), and Callback plugins (add new behaviors).

Key facts

Flashcards

What is the primary connection method Ansible uses to communicate with managed nodes?
SSH
tap to reveal
What file defines the hosts and groups that Ansible manages?
Inventory (file)
tap to reveal
What are the executable units of code that Ansible runs on managed nodes?
Modules
tap to reveal
What is a YAML file that orchestrates a series of tasks and plays?
Playbook
tap to reveal
What information does Ansible automatically gather about managed nodes that can be used in playbooks?
Facts (gathered by the `setup` module)
tap to reveal
What command is used to run a single Ansible task on managed hosts without a playbook?
`ansible` (ad-hoc command)
tap to reveal
What property ensures that running a task multiple times yields the same result without unintended side effects?
Idempotence
tap to reveal
In a playbook, what block maps a set of tasks to a specific group of hosts?
A Play
tap to reveal
Practice questions

Ansible Core Components: 5 practice questions

Q1. In a default Ansible installation on a Red Hat Enterprise Linux system, where is the primary, system-wide inventory file located?
  • A.  /var/lib/ansible/hosts
  • B.  /etc/ansible/hosts
  • C.  /etc/ansible/inventory
  • D.  ~/.ansible/hosts
Show answer & explanation
✓ Answer: B. /etc/ansible/hosts
The default system-wide inventory file is located at /etc/ansible/hosts, which is used to define the managed nodes Ansible can connect to.
Q2. Which ad-hoc command correctly uses the `ping` module to verify Ansible can connect and execute a basic module on all hosts defined in the inventory?
  • A.  ansible-playbook all -m ping
  • B.  ansible all -m ping
  • C.  ansible ping all
  • D.  ansible all --module ping
Show answer & explanation
✓ Answer: B. ansible all -m ping
The `ansible` command is used for ad-hoc tasks. The correct syntax is `ansible <host-pattern> -m <module>`, making `ansible all -m ping` the proper format.
Q3. Ansible looks for its configuration file (`ansible.cfg`) in several locations. According to the standard precedence order, which of the following locations is checked LAST?
  • A.  ./ansible.cfg (in the current directory)
  • B.  The path specified by the ANSIBLE_CONFIG environment variable
  • C.  /etc/ansible/ansible.cfg
  • D.  ~/.ansible.cfg (in the user's home directory)
Show answer & explanation
✓ Answer: C. /etc/ansible/ansible.cfg
Ansible's configuration file precedence is: ANSIBLE_CONFIG variable, ./ansible.cfg, ~/.ansible.cfg, and finally /etc/ansible/ansible.cfg. The system-wide file has the lowest priority.
Q4. Within an Ansible playbook, what is the primary purpose of a `handler`?
  • A.  To gather facts about the remote system before any tasks are executed.
  • B.  To handle errors and exceptions that occur during a playbook run.
  • C.  To define a reusable block of tasks that can be included anywhere.
  • D.  To run a task only when triggered by a `notify` directive from another task.
Show answer & explanation
✓ Answer: D. To run a task only when triggered by a `notify` directive from another task.
Handlers are special tasks that only execute when notified by a state change in another task, typically used for actions like restarting a service after a configuration update.
Q5. Which Ansible command would you use to view the documentation and example usage for the `dnf` module directly on the command line?
  • A.  ansible-help dnf
  • B.  ansible-doc -e dnf
  • C.  ansible-doc dnf
  • D.  ansible --doc dnf
Show answer & explanation
✓ Answer: C. ansible-doc dnf
The `ansible-doc` command is the built-in tool for displaying detailed documentation and examples for installed Ansible modules directly from the terminal.
Test yourself
See the Red Hat Certified Engineer (RHCE) exam (EX294) page

More Red Hat Certified Engineer (RHCE) exam (EX294) topics