RHCE: automation with Ansible
You learn to configure many servers at once, repeatably, with Ansible, using roles and encrypted secrets.
Level 301 · 25 lessons · 21 practice labs
Lessons
Project, inventory and access
- Preparing an Ansible project with Git: You will lay out playbooks, inventory and settings in a tidy project directory and version it with Git.
- ansible.cfg and project defaults: You will set inventory, user and privilege defaults in ansible.cfg and see which file is in effect.
- ansible-navigator and execution environments: You will run a playbook inside an execution environment with ansible-navigator and inspect its output.
- Offline documentation with ansible-doc: You will find a module’s parameters and examples with ansible-doc without internet and apply them in a playbook.
- Static inventory: groups and variables: You will write an inventory file that sorts servers into groups and carries group-specific variables.
- SSH keys and privilege escalation (become): You will connect to managed nodes with keys and use become to escalate privileges only when needed.
- Testing nodes with one-line ad hoc commands: You will use the ansible command to run quick jobs like ping and file checks across a whole group.
- Selecting targets with host patterns and limits: You will use patterns and --limit to make a job run only on selected servers.
- Short task: build a four-node inventory and prove you reach every node with privileges
Writing playbooks
- A first playbook: idempotent modules: You will run the same playbook twice with package, file and service modules and confirm the second run changes nothing.
- Restarting a service only on change with handlers: You will define a handler that fires when a config file changes and avoid needless restarts.
- Loops, facts and conditionals: You will apply different tasks depending on a server’s operating system with loop and when.
- Capturing results with register and controlling task status: You will store a task’s output in a variable and judge the result with your own criteria using failed_when and changed_when.
- Error handling with block, rescue and always: You will write a block structure that runs recovery tasks when a step fails.
- Debugging playbook errors: YAML, Jinja2 and module faults: You will locate and fix faults using syntax checks, --check and -vvv.
- Short task: write a playbook that installs a web server and rolls back on failure
Variables, templates, roles and collections
- Variables, facts and precedence: You will see which value wins when a variable is defined in several places and resolve conflicts.
- Creating custom facts: You will leave a fact file on a server and use it in a playbook through ansible_local.
- Generating configuration files with Jinja2 templates: You will insert server-specific values into a template and produce the right configuration file for each node.
- Protecting secrets with Ansible Vault: You will keep passwords in an encrypted file and use them safely while a playbook runs.
- Splitting playbooks with import and include: You will split a large playbook into reusable parts and explain static versus dynamic inclusion.
- Creating a reusable role: You will generate a role skeleton with ansible-galaxy and gather tasks, handlers and templates in it.
- Installing and using roles and collections: You will install a ready-made role and collection and use its module by full name in a playbook.
- Short task: write and share a role that creates users with encrypted passwords
Practice
- Capstone: automating packages, services, firewall, users and storage: You will configure packages, services, firewall, users, scheduled jobs and storage on several servers with one playbook.
Practice labs
- Write an inventory that groups four nodes: You write a static inventory with web, database and test groups and verify its graph with ansible-inventory.
- Prepare a node with one-line commands: With ad hoc commands you install a package, start a service and copy a file on managed nodes and verify the result.
- Select targets with group variables and patterns: You split group and host variables into directories and run a command on only the two required nodes using intersection and exclusion patterns.
- Prepare an ansible.cfg for a project: You write an ansible.cfg defining the inventory path, remote user and roles directory and list the effective settings with ansible-config.
- Set up passwordless privilege escalation on the nodes: You distribute the automation user's SSH key and sudoers entry to three nodes and prove an admin command runs with become.
- Run a playbook in an execution environment: You write an ansible-navigator settings file to use a local execution environment image, run the playbook and review the run artefact.
- Write a playbook that installs a package and starts a service: You write a playbook that installs the time sync package, enables its service and reports no change on a second run.
- Reload the service through a handler when a setting changes: You write a playbook with a handler that changes an SSH server setting with lineinfile and reloads the service only on change.
- Convert command tasks to idempotent modules: You rewrite a playbook full of shell tasks that report change every run using proper modules and get zero changes on the second run.
- Create packages and users with a loop: You write a short playbook that installs five packages and creates three users from a variable list with loops.
- Run tasks conditionally on node facts: You write conditional tasks copying different settings files by memory size and distribution version facts and compare the result on two nodes.
- Register a result and retry until ready: You write tasks that poll a service's health URL until it answers, register the result and define your own failure condition.
- Repair a playbook with broken syntax: You find indentation and quoting errors in a playbook with a syntax check and make it run.
- Roll back a failed database install with rescue: You write a playbook that installs a database in a block, removes the package and leaves a warning file on error and always writes a log.
- Solve a playbook that fails only on some nodes: You trace with verbose output and debug a playbook failing on two nodes over an undefined variable and a wrong Jinja2 filter and fix it.
- Generate a login message from a template: You deploy an /etc/motd containing each node's name, IP address and memory size with a Jinja2 template.
- Generate a hosts file for every node: With a template looping over all inventory nodes you generate the same /etc/hosts on every machine and test name resolution.
- Generate conditional config from a custom fact: You place a custom fact file declaring each node's role, generate different web server settings from it in a template and apply them with a handler.
- Encrypt a password file with Vault: You encrypt a variables file holding user passwords with ansible-vault and run the playbook using a vault password file.
- Write a reusable role for a web server: You create a role skeleton with tasks, handlers, a template and defaults and apply it to two nodes with two different ports.
- Install roles and collections from a requirements file: You install a role and a collection from local archives with requirements.yml, then configure time sync with a system role and a user with a vaulted variable.
About this course
You learn to configure many servers at once, repeatably, with Ansible, using roles and encrypted secrets.
What you will learn
- Project, inventory and access
- Writing playbooks
- Variables, templates, roles and collections
- Practice
Prerequisites
You should be comfortable with the level 101 and 201 topics of the same path.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at level 301; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.