## 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.
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