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

System Administration with Ansible Modules: Red Hat Certified Engineer (RHCE) exam (EX294) revision notes

Revision notes

## System Administration with Ansible Modules

The Red Hat Certified Engineer (RHCE) exam (EX294) heavily emphasizes using Ansible modules to automate common system administration tasks. Ansible is an agentless automation engine, meaning it doesn't require special software on managed nodes, relying on SSH for communication. Playbooks, written in YAML, define the desired state of your systems.

## Key Ansible Concepts

  • Playbooks: YAML files containing one or more plays. Each play targets a group of hosts from the inventory and defines a series of tasks.
  • Tasks: Calls to specific Ansible modules. Each task performs a single operation, e.g., installing a package or creating a user.
  • Modules: The core units of work in Ansible. They are idempotent, meaning running them multiple times with the same parameters will achieve the same result without unnecessary changes.
  • Inventory: A list of managed hosts, typically defined in an INI or YAML file. Hosts can be grouped for easier management.
  • Handlers: Special tasks that are only triggered when explicitly notified by another task, typically after a change occurs (e.g., restarting a service after a configuration file update).

## Essential Modules for RHCE

You'll need proficiency with various modules to manage RHEL systems:

  • Package Management: The `dnf` module (or `yum` for older RHEL) is crucial for installing, updating, and removing packages and managing repositories.

```yaml

  • name: Ensure httpd is installed

dnf:

name: httpd

state: present

```

  • Service Management: The `systemd` module manages services. Use `state: started/stopped`, `enabled: yes/no` to control their runtime and boot behavior.

```yaml

  • name: Start and enable httpd service

systemd:

name: httpd

state: started

enabled: yes

```

  • User and Group Management: The `user` and `group` modules create, modify, or delete system users and groups, managing properties like UID, GID, and shell.
  • File Management:
  • `file`: Manages files, directories, and symlinks (permissions, ownership, state).
  • `copy`: Copies files from the control node to managed hosts.
  • `template`: Renders Jinja2 templates on the control node and deploys them to managed hosts, allowing for dynamic configuration.
  • `lineinfile`/`blockinfile`: Modify specific lines or blocks within text files.
  • Storage Management: Modules like `lvg`, `lvol`, `filesystem`, and `mount` are used to create and manage Logical Volumes, filesystems, and mount points.
  • Firewall Management: The `firewalld` module configures firewall rules, zones, and services.
  • SELinux Management: The `selinux` module sets SELinux booleans or file contexts.
  • Cron Jobs: The `cron` module manages scheduled tasks.

Mastering these modules and understanding playbook structure is key to passing the RHCE exam.

Key facts

Flashcards

What is the primary communication method Ansible uses with managed nodes?
SSH (it is agentless).
tap to reveal
What file format are Ansible playbooks written in?
YAML (YAML Ain't Markup Language).
tap to reveal
Which Ansible module is used to install, update, or remove packages on RHEL 8/9?
The `dnf` module (or `yum` for older RHEL).
tap to reveal
How do you ensure a service like `httpd` is started and enabled at boot using Ansible?
Use the `systemd` module with `state: started` and `enabled: yes`.
tap to reveal
Which Ansible module allows you to deploy configuration files that include dynamic variables?
The `template` module, which uses Jinja2 templating.
tap to reveal
What is the purpose of an Ansible handler?
Handlers are tasks that are only run when explicitly `notify`-ed by another task, typically after a change.
tap to reveal
Which module would you use to create a directory, set its permissions, and ownership?
The `file` module.
tap to reveal
What does "idempotence" mean in the context of Ansible modules?
Running a module multiple times with the same parameters will achieve the same desired state without making unnecessary changes after the first successful run.
tap to reveal
Practice questions

System Administration with Ansible Modules: 5 practice questions

Q1. Which Ansible task correctly ensures the 'httpd' package is installed and enabled to start on boot using the generic, system-agnostic modules?
  • A.  ansible.builtin.dnf: name: httpd state: latest ansible.builtin.systemd: name: httpd state: running enabled: true
  • B.  ansible.builtin.package: name: httpd state: present ansible.builtin.service: name: httpd state: started enabled: yes
  • C.  ansible.builtin.command: dnf install -y httpd && systemctl enable --now httpd
  • D.  ansible.builtin.yum: name: httpd state: installed ansible.builtin.service: name: httpd status: enabled
Show answer & explanation
✓ Answer: B. ansible.builtin.package: name: httpd state: present ansible.builtin.service: name: httpd state: started enabled: yes
This uses two distinct, idempotent tasks. `ansible.builtin.package` is the generic module for package management, and `ansible.builtin.service` correctly ensures the service is running (`started`) and will start on boot (`enabled: yes`).
Q2. You need to add a line 'PermitRootLogin no' to the '/etc/ssh/sshd_config' file. If a line starting with 'PermitRootLogin' already exists, it must be replaced. Which task is the most idiomatic and correct way to achieve this?
  • A.  ansible.builtin.replace: path: /etc/ssh/sshd_config regexp: '^PermitRootLogin.*' replace: 'PermitRootLogin no'
  • B.  ansible.builtin.lineinfile: path: /etc/ssh/sshd_config regexp: '^PermitRootLogin' line: 'PermitRootLogin no'
  • C.  ansible.builtin.lineinfile: path: /etc/ssh/sshd_config line: 'PermitRootLogin no'
  • D.  ansible.builtin.blockinfile: path: /etc/ssh/sshd_config block: 'PermitRootLogin no'
Show answer & explanation
✓ Answer: B. ansible.builtin.lineinfile: path: /etc/ssh/sshd_config regexp: '^PermitRootLogin' line: 'PermitRootLogin no'
The `lineinfile` module with the `regexp` parameter is designed for this exact scenario. It searches for a line matching the regular expression and replaces it with the specified `line`. If no match is found, it adds the line.
Q3. Which task correctly creates a system user named 'app_runner' with a specific UID of 808, a home directory of '/srv/app', and prevents the creation of a mail spool file?
  • A.  ansible.builtin.user: name: app_runner uid: 808 home: /srv/app shell: /sbin/nologin no_mail: true
  • B.  ansible.builtin.user: name: app_runner uid: 808 home: /srv/app system: yes
  • C.  ansible.builtin.user: name: app_runner uid: 808 home: /srv/app system: yes create_mail_spool: no
  • D.  ansible.builtin.user: name: app_runner id: 808 directory: /srv/app system: true mail: false
Show answer & explanation
✓ Answer: C. ansible.builtin.user: name: app_runner uid: 808 home: /srv/app system: yes create_mail_spool: no
The `ansible.builtin.user` module uses specific parameters: `uid` for user ID, `home` for the home directory, `system=yes` for a system account, and `create_mail_spool=no` to prevent mail file creation.
Q4. How do you use an Ansible module to ensure the directory '/opt/data' exists with permissions '0750', is owned by the 'devops' user, and belongs to the 'developers' group?
  • A.  ansible.builtin.file: path: /opt/data state: present permissions: '0750' user: devops group: developers
  • B.  ansible.builtin.file: path: /opt/data state: directory mode: '0750' owner: devops group: developers
  • C.  ansible.builtin.mkdir: path: /opt/data mode: '0750' owner: devops group: developers
  • D.  ansible.builtin.copy: dest: /opt/data state: directory mode: '0750' owner: devops group: developers
Show answer & explanation
✓ Answer: B. ansible.builtin.file: path: /opt/data state: directory mode: '0750' owner: devops group: developers
The `ansible.builtin.file` module is the correct tool for managing file and directory properties. `state: directory` ensures it's a directory, and the `mode`, `owner`, and `group` parameters set the permissions and ownership.
Q5. Which task correctly creates a 2GiB LVM logical volume named 'web_data' in the volume group 'vg_storage' and formats it with the xfs filesystem?
  • A.  community.general.filesystem: vg: vg_storage lv: web_data size: 2g fstype: xfs
  • B.  community.general.lvol: vg: vg_storage lv: web_data size: 2048 fstype: xfs
  • C.  - community.general.lvol: vg: vg_storage lv: web_data size: 2g - community.general.filesystem: fstype: xfs dev: /dev/vg_storage/web_data
  • D.  community.general.lvol: vg: vg_storage lv: web_data size: 2g opts: '--mkfs.xfs'
Show answer & explanation
✓ Answer: C. - community.general.lvol: vg: vg_storage lv: web_data size: 2g - community.general.filesystem: fstype: xfs dev: /dev/vg_storage/web_data
Creating and formatting a logical volume are two separate, sequential actions in Ansible. First, `community.general.lvol` creates the volume, then `community.general.filesystem` formats the newly created device.
Test yourself
See the Red Hat Certified Engineer (RHCE) exam (EX294) page

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