Ansible Assignment– 3

Ansible Modules & Collections

Basic Questions

  1. Write a Playbook using the file module to create a directory /opt/demo.
  2. Write a Playbook using the file module to delete the directory /opt/demo.
  3. Write a Playbook using the package module to install git.
  4. Write a Playbook using the package module to remove nginx.
  5. Write a Playbook using the service module to start the Apache service.
  6. Write a Playbook using the service module to stop the Apache service.
  7. Write a Playbook using the service module to enable MySQL service on boot.
  8. Write a Playbook using the user module to create a user ansibleuser.
  9. Write a Playbook using the user module to remove the user ansibleuser.
  10. Write a Playbook using the copy module to copy a text file to /tmp on managed nodes.
  11. Write a Playbook using the copy module to copy a configuration file with permissions set to 0644.
  12. Write a Playbook using the template module to deploy a configuration file with Jinja2 variables.
  13. Write a Jinja2 template that prints the hostname of the managed node.
  14. Write a Jinja2 template that prints the IP address of the managed node.
  15. Write a Playbook that applies a template with multiple variables (e.g., server name, port).
  16. Install a role from Ansible Galaxy using ansible-galaxy install.
  17. List all installed collections on your system.
  18. Write a Playbook that uses the ping module on all hosts.
  19. Write a Playbook that uses the debug module to print a custom message.
  20. Write a Playbook using at least 5 modules: file, package, service, user, and copy.

Intermediate Questions

  1. Write a Playbook that creates multiple directories using the file module with a loop.
  2. Write a Playbook that installs multiple packages using the package module with a loop.
  3. Write a Playbook that starts and enables multiple services (Apache, MySQL) using the service module.
  4. Write a Playbook that creates multiple users using the user module with a loop.
  5. Write a Playbook that copies multiple files using the copy module with a loop.
  6. Write a Playbook that uses a Jinja2 template to generate a configuration file with variables for host and port.
  7. Write a Jinja2 template that prints a list of users defined in a variable.
  8. Write a Jinja2 template that prints a dictionary of application settings.
  9. Write a Playbook that deploys the template and restarts Apache using a handler.
  10. Install a collection from Ansible Galaxy and use it in a Playbook.
  11. Write a Playbook that uses a module from a Galaxy collection.
  12. Write a Playbook that installs packages only if the OS is Ubuntu (conditionals with package module).
  13. Write a Playbook that installs packages only if the OS is CentOS.
  14. Write a Playbook that creates users with different shells using variables.
  15. Write a Playbook that copies a template file and sets owner, group, and permissions.
  16. Write a Playbook that installs and configures Apache using both package and template modules.
  17. Write a Playbook that creates multiple directories under /var/www with the file module.
  18. Write a Playbook that uses the lineinfile module to update a configuration file.
  19. Write a Playbook that uses the replace module to change content inside a file.
  20. Write a Playbook using 7 modules together: file, package, service, user, copy, template, and debug.

Advanced Questions

  1. Write a Playbook that creates multiple users with home directories and SSH keys.
  2. Write a Playbook that deploys an application configuration file using Jinja2 templates with loops and conditionals.
  3. Write a Playbook that uses facts in a Jinja2 template to set different port values for Ubuntu and CentOS.
  4. Write a Playbook that installs Apache using a Galaxy role and configures it using a template.
  5. Write a Playbook that installs MySQL using a Galaxy role and configures users using the user module.
  6. Write a Playbook that uses a module from the community.general collection.
  7. Write a Playbook that installs Nginx, configures it using a template, and enables the service.
  8. Create a custom Ansible module in Python that prints “Hello Custom Module”.
  9. Create a custom Ansible module in PowerShell that prints system information on a Windows node.
  10. Write a complete Playbook: Install Apache → Copy template index.html → Create web user → Start Apache → Verify service.