This repository contains solutions for Ansible lab tasks from KodeKloud, organized by difficulty levels (Levels 1β4). All tasks in Levels 1 to 4 are completed, with each task documented in a detailed Markdown file containing step-by-step instructions, inventory and playbook configurations, verification commands, troubleshooting tips, and production notes. These solutions are designed to assist the Nautilus DevOps team in automating server management tasks efficiently in Stratos DC.
Important Note: When starting any Ansible task, users are already logged into the Jump Host by default as the thor user. The SSH command to connect (e.g., ssh thor@jumphost) is included for educational purposes. This repository serves as a comprehensive record of my learning experience through the KodeKloud Engineer challenge, showcasing real-world Ansible tasks and projects designed to build practical DevOps expertise. The tasks reflect specific challenges encountered, with detailed solutions and verification steps.
Caveat: While the core objectives and approaches remain consistent, specific values (e.g., server names, IP addresses, file paths, or credentials) may differ in your environment. The concepts and problem-solving strategies provided here are adaptable to your specific context.
π Purpose: Provide clear, executable solutions for Ansible labs, ensuring best practices and alignment with task requirements.
π οΈ Tools Used:
- Ansible: Managed via
ansibleandansible-playbookon the jump host. - Modules:
yum,service,copy,file,template,replace,user,group,ping,archive,unarchive,blockinfile,lineinfilefor package, service, file, and user management. - Environment: KodeKloud lab environment with pre-installed Ansible.
KodeKloud-Ansible-Solutions/
βββ level-1/
β βββ task01-install-package.md
β βββ task02-install-httpd.md
β βββ task03-configure-ansible-remote-user.md
β βββ task04-copy-index-html.md
β βββ task05-create-file-with-permissions.md
βββ level-2/
β βββ task01-ping-module-usage.md
β βββ task02-install-package.md
β βββ task03-archive-module.md
β βββ task04-unarchive-module.md
β βββ task05-blockinfile-module.md
βββ level-3/
β βββ task01-create-soft-links.md
β βββ task02-manage-acls.md
β βββ task03-manage-services.md
β βββ task04-lineinfile-module.md
β βββ task05-replace-module.md
βββ level-4/
β βββ task01-facts-gathering.md
β βββ task02-create-users-groups.md
β βββ task03-deploy-httpd-role.md
β βββ task04-setup-apache-php.md
β βββ task05-copy-files-conditionals.md
βββ README.md
| Task # | Title/Link | Status | Difficulty | Description |
|---|---|---|---|---|
| 1 | Install Package | β Done | π’ Basic | Install httpd package on App Server 1 using Ansible playbook |
| 2 | Install httpd | β Done | π’ Basic | Install and start httpd on App Server 3 |
| 3 | Configure Ansible Remote User | β Done | π’ Basic | Set james as default SSH user in Ansible config |
| 4 | Copy index.html | β Done | π’ Basic | Copy index.html to /opt/itadmin/ on all app servers |
| 5 | Create File with Permissions | β Done | π‘ Intermediate | Create /usr/src/app.txt with 0777 permissions and specific ownership |
| Task # | Title/Link | Status | Difficulty | Description |
|---|---|---|---|---|
| 1 | Ansible Ping Module Usage | β Done | π‘ Intermediate | Test connectivity to app servers using the Ansible ping module |
| 2 | Ansible Install Package | β Done | π‘ Intermediate | Install a specified package on app servers using Ansible |
| 3 | Ansible Archive Module | β Done | π‘ Intermediate | Create an archive of files or directories using the archive module |
| 4 | Ansible Unarchive Module | β Done | π‘ Intermediate | Extract an archive to a specified location using the unarchive module |
| 5 | Ansible Blockinfile Module | β Done | π‘ Intermediate | Insert or update a block of text in a file using the blockinfile module |
| Task # | Title/Link | Status | Difficulty | Description |
|---|---|---|---|---|
| 1 | Creating Soft Links Using Ansible | β Done | π Advanced | Create symbolic links on app servers using Ansible |
| 2 | Managing ACLs Using Ansible | β Done | π Advanced | Configure access control lists (ACLs) for files or directories |
| 3 | Ansible Manage Services | β Done | π Advanced | Manage service states (start, stop, enable) on app servers |
| 4 | Ansible Lineinfile Module | β Done | π Advanced | Modify specific lines in files using the lineinfile module |
| 5 | Ansible Replace Module | β Done | π Advanced | Replace text in files using the replace module |
| Task # | Title/Link | Status | Difficulty | Description |
|---|---|---|---|---|
| 1 | Ansible Facts Gathering | β Done | π Advanced | Gather and store Ansible facts from App Server 1 |
| 2 | Ansible Create Users and Groups | β Done | π Advanced | Create users and groups on App Server 2 with specific permissions |
| 3 | Managing Jinja2 Templates Using Ansible | β Done | π Advanced | Deploy httpd on App Server 1 using a role with a dynamic index.html |
| 4 | Ansible Setup Httpd and PHP | β Done | π Advanced | Install httpd and php, configure custom document root, deploy phpinfo.php |
| 5 | Using Ansible Conditionals | β Done | π Advanced | Copy specific files to app servers using conditionals based on inventory_hostname |
-
Clone the Repository:
git clone https://github.com/MiqdadProjects/KodeKloud-Ansible-Solutions.git cd KodeKloud-Ansible-Solutions -
Navigate to Task Files:
- Level 1 tasks:
level-1/ - Level 2 tasks:
level-2/ - Level 3 tasks:
level-3/ - Level 4 tasks:
level-4/
- Level 1 tasks:
-
Apply Solutions:
- Copy the inventory, playbook, and template content from each taskβs Markdown file.
- Create files on the jump host (e.g.,
vi ~/ansible/inventory,vi ~/ansible/playbook.yml,vi ~/ansible/roles/httpd_role/templates/index.html.j2). - Run playbooks with:
ansible-playbook -i inventory playbook.yml
- Follow verification steps (e.g.,
ssh,ls -la,systemctl status,curl) to ensure success.
-
Troubleshooting:
- Refer to the Troubleshooting Common Issues section in each task file.
- Use commands like
ansible-playbook -voransible --versionfor debugging. - Check the
troubleshooting/Common-Issues-Solutions.mdfile (TBD) for common fixes.
-
Test in Lab Environment:
- Use the jump host (
ssh thor@jumphost) with pre-configured Ansible. - Verify tasks using SSH to app servers and checking file or service states.
- Use the jump host (
- Ansible Installation: Pre-installed on the jump host via
yum. - Text Editor:
vior similar for editing inventory, playbook, and template files. - Git: For version control and repository management.
- Lab Environment: KodeKloud lab with pre-configured jump host and app servers.
-
Access the Jump Host:
ssh thor@jumphost
-
Create and Edit Files:
cd ~/ansible vi inventory vi playbook.yml # For roles/templates (e.g., Level 4 TASK03, TASK04) mkdir -p roles/httpd_role/templates vi roles/httpd_role/templates/index.html.j2 # Paste content from taskβs Markdown file # Save with :wq
-
Run Playbooks:
ansible-playbook -i inventory playbook.yml
-
Verify Results:
ssh <user>@<server> ls -la <path> systemctl status <service> cat <file> curl http://localhost/<file>
-
Debug Issues:
- Check playbook syntax:
ansible-playbook -i inventory playbook.yml --syntax-check - View verbose output:
ansible-playbook -i inventory playbook.yml -v - Test connectivity:
ssh <user>@<ip>
- Check playbook syntax:
- Filenames: Task files use the format
taskXX-descriptive-name.mdfor clarity and VS Code compatibility. - Security: Avoid plain-text passwords (
ansible_ssh_pass) in production; use SSH keys or Ansible Vault. - Dry Runs: Test playbooks with
--checkto simulate changes:ansible-playbook -i inventory playbook.yml --check
- Production Readiness: Each task includes production notes for real-world considerations (e.g., SELinux, SSL/TLS, logging).
- Level Completion: All tasks in Levels 1β4 are completed.
Contributions are welcome! To add improvements or update documentation:
- Fork the repository.
- Create a new branch:
git checkout -b update-level-X
- Update Markdown files in the appropriate level directory.
- Commit changes:
git commit -m "Update Level X task solutions" - Push to the branch:
git push origin update-level-X
- Open a pull request with a detailed description of changes.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions, issues, or task details, contact the Nautilus DevOps team or open an issue in the repository.
Happy Automating with Ansible! π