Ansible Assignment– 4
Roles & Reusability
Basic Questions
- Create a new Ansible Role named webserver.
- Generate the default directory structure of a Role using ansible-galaxy init.
- List all the directories and files created when initializing a Role.
- Create a Role that installs Apache using the package module.
- Add a task in the Role to start the Apache service.
- Add a task in the Role to enable Apache service on boot.
- Create a Role that installs MySQL using the package module.
- Add a handler in the Role to restart Apache after configuration changes.
- Create a Role that creates a user named deploy.
- Use the Role webserver in a Playbook to install Apache on a managed node.
- Use the Role database in a Playbook to install MySQL on a managed node.
- Create a Playbook that applies both webserver and database Roles.
- Create a Role variable for Apache package name and use it in tasks.
- Create a Role variable for MySQL package name and use it in tasks.
- Add a default variable in the Role and print it using the debug module.
- Import a task file into a Role and run it.
- Use include_tasks to import a task dynamically inside a Role.
- Add a template file in a Role to configure Apache.
- Copy a static file using a Role.
- Run the Role and verify that all tasks execute successfully.
Intermediate Questions
- Create a Role that installs Nginx and deploys a custom index.html.
- Add handlers in the Role to restart Nginx when index.html changes.
- Create a Role that installs multiple packages using a loop.
- Add a Role that creates multiple users using a loop.
- Import tasks from another Role into the current Role.
- Reuse the webserver Role across two different Playbooks.
- Create a Role with group variables for different server groups.
- Create a Role with host-specific variables.
- Use vars_files inside a Role to include external variable files.
- Create a Role that configures Apache Virtual Hosts using templates.
- Create a Role that configures MySQL database users using variables.
- Use tags to run only specific tasks from a Role.
- Run a Playbook and skip tasks from a Role using tags.
- Use a Role downloaded from Ansible Galaxy in your Playbook.
- Customize a Galaxy Role by overriding default variables.
- Create a Role that deploys a simple static web app (HTML files).
- Add a handler in the Role to restart Apache only when configuration changes.
- Create a Role that installs and configures firewalld service.
- Reuse tasks from the common Role in the webserver Role.
- Combine multiple Roles (common, webserver, database) in one Playbook.
Advanced Questions
- Create a reusable Role that deploys a web application using Apache.
- Extend the Role to deploy the same application on Nginx as an alternative.
- Add templates, handlers, and variables in the Role for flexible configuration.
- Create a Role that deploys a database schema to MySQL.
- Import common tasks (like creating directories) into multiple Roles.
- Download and use a Galaxy Role to configure a load balancer.
- Create a Role that configures SSL certificates for Apache.
- Write a Playbook that applies multiple Roles (webserver, database, firewall) for a complete stack deployment.
- Create a Role that deploys a multi-tier web app with separate tasks for frontend, backend, and database.
- Develop a full reusable Role: Install Apache → Copy application files → Configure Virtual Hosts → Start service → Notify handler → Deploy app.