Ansible Assignment– 2

Playbooks & Tasks

Basic Questions

  1. Create a simple Ansible Playbook that prints “Hello Ansible Playbook”.
  2. Write a Playbook that installs the Apache web server on a managed node.
  3. Write a Playbook that installs MySQL on a managed node.
  4. Create a Playbook that creates a new user on all managed nodes.
  5. Create a Playbook that creates a directory /opt/ansible_test on managed nodes.
  6. Write a Playbook that copies a text file from the control node to managed nodes.
  7. Write a Playbook that starts the Apache service after installation.
  8. Write a Playbook that stops the Apache service.
  9. Write a Playbook that restarts the Apache service.
  10. Write a Playbook that updates all packages on a managed node.
  11. Write a Playbook that prints all system facts of a managed node.
  12. Write a Playbook that installs multiple packages (e.g., git, curl, wget).
  13. Write a Playbook that removes a package (e.g., nginx).
  14. Write a Playbook with variables for package name and service name.
  15. Write a Playbook that uses a variable for the username and creates that user.
  16. Write a Playbook that displays the hostname of all managed nodes.
  17. Write a Playbook that runs a shell command to check disk space.
  18. Write a Playbook with two tasks: install Apache and start Apache.
  19. Write a Playbook that installs Apache only on web server group from the inventory.
  20. Write a Playbook that installs MySQL only on db server group from the inventory.

Intermediate Questions

  1. Write a Playbook that installs Apache only if the OS is Ubuntu (using conditionals).
  2. Write a Playbook that installs Nginx only if the OS is CentOS (using conditionals).
  3. Write a Playbook that creates multiple users using a loop.
  4. Write a Playbook that installs multiple packages using a loop.
  5. Write a Playbook with a handler to restart Apache after installation.
  6. Write a Playbook with a handler to restart MySQL after installation.
  7. Write a Playbook with a notification that triggers a handler only when a file changes.
  8. Write a Playbook that uses tags for package installation tasks.
  9. Write a Playbook that uses tags for service management tasks.
  10. Run a Playbook and execute only the tasks with tag install.
  11. Run a Playbook and skip all tasks with tag service.
  12. Write a Playbook that installs Apache and configures index.html using copy module.
  13. Write a Playbook that installs MySQL and sets the root password using variables.
  14. Write a Playbook that uses when condition to run only on specific host group.
  15. Write a Playbook that prints the IP address of managed nodes using facts.
  16. Write a Playbook with two plays: one for web servers and one for db servers.
  17. Write a Playbook that installs and enables firewalld service.
  18. Write a Playbook that disables firewalld service.
  19. Write a Playbook that installs Git and clones a repository.
  20. Write a Playbook that creates a cron job for a user.

Advanced Questions

  1. Write a Playbook that installs Apache and deploys a custom website with handlers.
  2. Write a Playbook that installs MySQL, creates a database, and a database user.
  3. Write a Playbook with loops to create multiple directories under /opt/apps.
  4. Write a Playbook that installs different packages on Ubuntu and CentOS servers using conditionals.
  5. Write a Playbook that applies tags for install, configure, and restart tasks separately.
  6. Write a Playbook that installs Apache and restarts it only if the configuration file changes.
  7. Write a Playbook that creates multiple users and assigns them to different groups using loops.
  8. Write a Playbook that configures Apache virtual hosts and restarts Apache using handlers.
  9. Write a Playbook that provisions both web and db servers together with different tasks.
  10. Write a complete Playbook: Install Apache → Copy index.html → Start Apache → Notify handler → Restart Apache.