
- A small Ansible project that installs httpd, deploys a template-based index.html, ensures the service is running, and restarts httpd when content changes.
- The playbook demonstrates inventory, ansible.cfg defaults, variables, tasks, templates, and handlers—the core building blocks of Ansible automation.
- Create a project folder and basic files.
- Define an inventory that targets the managed host(s).
- Add a minimal ansible.cfg so you don’t need extra CLI flags.
- Write a playbook with tasks and handlers.
- Run the playbook and verify the result on the managed host.
Ensure the Ansible remote user can perform privileged tasks. In this lab the sudoers entry allows the student user to use sudo without a password:
Be careful granting NOPASSWD sudo in production. Use the minimum required privileges and restrict commands where possible.
- Install Ansible on the control host. The example below uses dnf on RHEL; replace with your platform’s package manager if needed.
- Create a project folder and enter it:
- Create an inventory file. This example defines a webservers group with servera. Adjust ansible_host if you need an explicit IP.
- Create a minimal ansible.cfg so you don’t need to pass —inventory or —user on the command line. Save this as ansible.cfg in the project folder.
Write the playbook
Create playbook.yml with the content below. The playbook installs the httpd package, deploys a simple index.html template, starts the httpd service, and notifies a handler to restart httpd when the template changes.
- Perform a syntax check:
- Run the playbook:
- Ansible Documentation
- Ansible Playbooks
- Jinja2 Template Documentation
- RHEL System Administration Guide