Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
What the course covers
Ansible from the first lesson. What it is, the main parts, and how to run it on RHEL servers.
- YAML, inventories, playbooks, tasks, modules, variables, facts, and loops.
- Modules for the main RHCE jobs: packages, files, templates, users, services, firewall, and storage.
- Roles, collections, Ansible Galaxy, and Ansible Vault.
- Real Linux admin jobs with Ansible: cron, SELinux, SSH keys, disks, repos, and network.
- A full mock RHCE exam with 11 tasks. It follows the EX294 exam style.
- Terminal skills: Vim, tmux,
ansible-navigator, andansible-doc. - How to write playbooks that are idempotent. Run them again and the end state is the same.
Welcome and lab setup
Three short lessons show how the course works.
- VIRGIL is an AI helper inside the lab. It knows which lab you are on.
- The lab runs in a browser. Each command has a copy icon. Paste it in the terminal.
Required tools: Vim and tmux
Vim has modes. Press i to type. Press Esc to stop. :wq saves and quits. :q! quits and drops the changes.
- tmux is a terminal multiplexer. It splits one window into many panes.
- A tmux command starts with
Ctrl-B. Then%makes a vertical split. You can move, zoom, and close panes.
Ansible overview
Ansible has parts that work together: modules, tasks, plays, playbooks, inventory, variables, Jinja, and handlers.
- A module does one job. A task calls a module. A play groups tasks. A playbook groups plays.
- The inventory says which hosts Ansible will touch.
Ansible basics
YAML is the language of playbooks. It has maps and lists. Indentation matters. # starts a comment.
- An inventory lists hosts and groups. The course uses both INI and YAML forms.
ansible-playbookruns a playbook.ansibleruns one ad-hoc command.ansible.cfgstores defaults, so you type less. Ansible looks for it in this order:ANSIBLE_CONFIG, then./ansible.cfg, then~/.ansible.cfg, then/etc/ansible/ansible.cfg.- Loops use
loop:with a list. Variables can come fromvars,vars_files, host vars,-e,vars_prompt,register, andset_fact. Precedence decides which value wins.
Critical modules and keywords
copy sends a file from the control node. It can also set owner, group, and mode.
filemakes files and folders, or removes them whenstateisabsent.templatefills a Jinja2 file and sends it.get_urldownloads a file with HTTP.urisends HTTP requests, for example a GET to a protected page.whenruns a task only if a test is true. Tags let you run part of a playbook with--tags,--skip-tags, or--list-tasks.
System essentials
ansible-navigator runs playbooks and reads module docs in a menu. It works well with Execution Environments.
dnfinstalls and removes packages.yum_repositoryadds, enables, or disables repos.- Facts are data Ansible collects about a host.
registersaves command output, andwhencan use it.
Advanced Ansible
Handlers run only when a task reports a change. A notify calls a handler by name. A listener can catch many notifies.
block,rescue, andalwaysgroup tasks and handle errors.- Collections and roles package content. Galaxy is the sharing site.
ansible-galaxyinstalls and creates them. - Vault encrypts files.
ansible-vaultcreates, encrypts, edits, and decrypts them.
System configuration
Add, enable, disable, and pin repos with yum_repository and dnf.
Users and security
group and user create accounts. A user can have a primary group and extra groups.
Services and networking
systemd starts, stops, enables, and disables services. Enable means "start at boot".
firewalldopens ports in a zone.permanent: yeskeeps the rule after a reboot.
Storage
parted makes partitions. filesystem formats them.
mountmounts a filesystem and writes/etc/fstab, so it comes back after a reboot.- Reboot and check that each mount point is still there.
Utilities, extras, and the mock exam
json_query filters data with JMESPath. set_fact stores the result.
archivemakes a compressed file.unarchiveextracts it.statpluswhenavoids repeat work.- A challenge asks you to turn three shell scripts into playbooks.
- The mock exam has 11 tasks: LVM storage, users and backups, a network bond, managed nodes, a script conversion, user loops, retry logic, a MOTD template, navigator use, an Apache role, and Vault.
Key commands and tools
ansible --version— show the version and the config file in use.ansible rhel_nodes -b -m shell -a '...'— run one ad-hoc command as root on a group.ansible-playbook site.yml— run a playbook.ansible-playbook site.yml -e "key=value"— pass extra variables.ansible-playbook site.yml --tags "configuration,packages"— run only some tags.ansible-playbook site.yml --skip-tags "packages"— skip some tags.ansible-playbook site.yml --tags "..." --list-tasks— preview which tasks will run.ansible-playbook site.yml --vault-password-file=~/mycode/.vaultpw— unlock Vault from a file.ansible-inventory -i inventory --list— show the hosts in an inventory.ansible-config dump— show the current config.ansible-doc copy— read the docs for a module in the terminal.ansible-navigator run site.yml— run a playbook in the navigator.ansible-navigator doc— read docs in the navigator.ansible-navigator collections/ansible-navigator inventory— browse content and hosts.ansible-galaxy collection install/ansible-galaxy role install— install content.ansible-galaxy init— make a role skeleton.ansible-vault create|encrypt|edit|decrypt— work with secret files.- Core modules:
copy,file,template,get_url,uri,dnf,yum_repository,systemd,firewalld,user,group,authorized_key,seboolean,parted,filesystem,mount,at,cron,lineinfile,blockinfile,archive,unarchive. - Data keywords:
loop,when,register,set_fact,lookup,json_query. - Block keywords:
block,rescue,always,notify,tags,become,gather_facts. - Jinja2 filters such as
password_hashfor user passwords. - Other tools: Vim, tmux,
pipx(for the navigator),nmcli,ausearch,audit2why,runcon,tree.
Key terms
The words of this course in one table. Learn them before the quiz or exam.
| Term | Meaning |
|---|---|
| Ansible | A tool that automates Linux admin work from one control node. |
| Ansible Galaxy | The public site for sharing roles and collections. |
| Collection | A package of modules, roles, and plugins. |
| Control node | The machine where you write and run Ansible. In this course it is bchd. |
| Execution Environment | A container image that holds Ansible and its tools. |
| Fact | Data Ansible gathers about a host, like its OS or memory. |
| Fully qualified module name | The long name of a module with its collection, like ansible.builtin.copy. |
| Handler | A task that runs only when another task notifies it. |
| Idempotent | Safe to run again. The end state stays the same and nothing extra changes. |
| Inventory | A list of hosts and groups. It can be INI or YAML. |
| Jinja2 | A template language. It adds variables, if, and for to text files. |
| Listener | A name that groups handlers, so one notify can start them all. |
| Loop | One task that runs again for each item in a list. |
| Managed node | A server that Ansible connects to and changes. |
| Module | A small program that does one job, like copy or dnf. |
| Play | One part of a playbook. It maps a group of hosts to a set of tasks. |
| Playbook | A YAML file with plays and tasks. |
| Role | A folder with tasks, handlers, vars, defaults, and meta for one job. |
| Tag | A label on a task. You can run only some tags with --tags. |
| Task | One step in a play. One module does the work. |
| Template | A text file with Jinja2 placeholders. The template module fills it in. |
| Variable | A named value that you reuse in a playbook. |
| Vault | The Ansible tool that encrypts secret files. |
when | A test that decides if a task runs. |
| YAML | A text format with lists and maps. Indentation is important. |
Check yourself
Answer each question first, then open it to check the answer.
1What does ansible.cfg do? Name one setting you can put in it.
It stores default settings for Ansible, so you do not type them every time. You can set the default inventory, a callback for output, or default tags to run or skip.
2What is the difference between ansible and ansible-playbook?
ansible runs one ad-hoc command on hosts. ansible-playbook runs a YAML file with one or more plays and many tasks.
3When does a handler run?
A handler runs only when a task notifies it. The notify fires at the end of a block of tasks, and the handler runs once, even if many tasks call it.
4How do you keep a firewalld rule after a reboot?
Open the port with the firewalld module and set permanent: yes. Without that, the rule is only in memory and is lost at boot.
5What is the difference between a role and a collection?
A role is a folder with tasks, handlers, vars, defaults, and meta for one job, like apache_webserver. A collection is a bigger package that can hold roles, modules, and plugins, like ansible.posix.
Useful links
Official documentation and pages for this course.