Ansible Assignment– 2
Playbooks & Tasks
Basic Questions
- Create a simple Ansible Playbook that prints “Hello Ansible Playbook”.
- Write a Playbook that installs the Apache web server on a managed node.
- Write a Playbook that installs MySQL on a managed node.
- Create a Playbook that creates a new user on all managed nodes.
- Create a Playbook that creates a directory /opt/ansible_test on managed nodes.
- Write a Playbook that copies a text file from the control node to managed nodes.
- Write a Playbook that starts the Apache service after installation.
- Write a Playbook that stops the Apache service.
- Write a Playbook that restarts the Apache service.
- Write a Playbook that updates all packages on a managed node.
- Write a Playbook that prints all system facts of a managed node.
- Write a Playbook that installs multiple packages (e.g., git, curl, wget).
- Write a Playbook that removes a package (e.g., nginx).
- Write a Playbook with variables for package name and service name.
- Write a Playbook that uses a variable for the username and creates that user.
- Write a Playbook that displays the hostname of all managed nodes.
- Write a Playbook that runs a shell command to check disk space.
- Write a Playbook with two tasks: install Apache and start Apache.
- Write a Playbook that installs Apache only on web server group from the inventory.
- Write a Playbook that installs MySQL only on db server group from the inventory.
Intermediate Questions
- Write a Playbook that installs Apache only if the OS is Ubuntu (using conditionals).
- Write a Playbook that installs Nginx only if the OS is CentOS (using conditionals).
- Write a Playbook that creates multiple users using a loop.
- Write a Playbook that installs multiple packages using a loop.
- Write a Playbook with a handler to restart Apache after installation.
- Write a Playbook with a handler to restart MySQL after installation.
- Write a Playbook with a notification that triggers a handler only when a file changes.
- Write a Playbook that uses tags for package installation tasks.
- Write a Playbook that uses tags for service management tasks.
- Run a Playbook and execute only the tasks with tag install.
- Run a Playbook and skip all tasks with tag service.
- Write a Playbook that installs Apache and configures index.html using copy module.
- Write a Playbook that installs MySQL and sets the root password using variables.
- Write a Playbook that uses when condition to run only on specific host group.
- Write a Playbook that prints the IP address of managed nodes using facts.
- Write a Playbook with two plays: one for web servers and one for db servers.
- Write a Playbook that installs and enables firewalld service.
- Write a Playbook that disables firewalld service.
- Write a Playbook that installs Git and clones a repository.
- Write a Playbook that creates a cron job for a user.
Advanced Questions
- Write a Playbook that installs Apache and deploys a custom website with handlers.
- Write a Playbook that installs MySQL, creates a database, and a database user.
- Write a Playbook with loops to create multiple directories under /opt/apps.
- Write a Playbook that installs different packages on Ubuntu and CentOS servers using conditionals.
- Write a Playbook that applies tags for install, configure, and restart tasks separately.
- Write a Playbook that installs Apache and restarts it only if the configuration file changes.
- Write a Playbook that creates multiple users and assigns them to different groups using loops.
- Write a Playbook that configures Apache virtual hosts and restarts Apache using handlers.
- Write a Playbook that provisions both web and db servers together with different tasks.
- Write a complete Playbook: Install Apache → Copy index.html → Start Apache → Notify handler → Restart Apache.