Ansible Assignment– 3
Ansible Modules & Collections
Basic Questions
- Write a Playbook using the file module to create a directory /opt/demo.
- Write a Playbook using the file module to delete the directory /opt/demo.
- Write a Playbook using the package module to install git.
- Write a Playbook using the package module to remove nginx.
- Write a Playbook using the service module to start the Apache service.
- Write a Playbook using the service module to stop the Apache service.
- Write a Playbook using the service module to enable MySQL service on boot.
- Write a Playbook using the user module to create a user ansibleuser.
- Write a Playbook using the user module to remove the user ansibleuser.
- Write a Playbook using the copy module to copy a text file to /tmp on managed nodes.
- Write a Playbook using the copy module to copy a configuration file with permissions set to 0644.
- Write a Playbook using the template module to deploy a configuration file with Jinja2 variables.
- Write a Jinja2 template that prints the hostname of the managed node.
- Write a Jinja2 template that prints the IP address of the managed node.
- Write a Playbook that applies a template with multiple variables (e.g., server name, port).
- Install a role from Ansible Galaxy using ansible-galaxy install.
- List all installed collections on your system.
- Write a Playbook that uses the ping module on all hosts.
- Write a Playbook that uses the debug module to print a custom message.
- Write a Playbook using at least 5 modules: file, package, service, user, and copy.
Intermediate Questions
- Write a Playbook that creates multiple directories using the file module with a loop.
- Write a Playbook that installs multiple packages using the package module with a loop.
- Write a Playbook that starts and enables multiple services (Apache, MySQL) using the service module.
- Write a Playbook that creates multiple users using the user module with a loop.
- Write a Playbook that copies multiple files using the copy module with a loop.
- Write a Playbook that uses a Jinja2 template to generate a configuration file with variables for host and port.
- Write a Jinja2 template that prints a list of users defined in a variable.
- Write a Jinja2 template that prints a dictionary of application settings.
- Write a Playbook that deploys the template and restarts Apache using a handler.
- Install a collection from Ansible Galaxy and use it in a Playbook.
- Write a Playbook that uses a module from a Galaxy collection.
- Write a Playbook that installs packages only if the OS is Ubuntu (conditionals with package module).
- Write a Playbook that installs packages only if the OS is CentOS.
- Write a Playbook that creates users with different shells using variables.
- Write a Playbook that copies a template file and sets owner, group, and permissions.
- Write a Playbook that installs and configures Apache using both package and template modules.
- Write a Playbook that creates multiple directories under /var/www with the file module.
- Write a Playbook that uses the lineinfile module to update a configuration file.
- Write a Playbook that uses the replace module to change content inside a file.
- Write a Playbook using 7 modules together: file, package, service, user, copy, template, and debug.
Advanced Questions
- Write a Playbook that creates multiple users with home directories and SSH keys.
- Write a Playbook that deploys an application configuration file using Jinja2 templates with loops and conditionals.
- Write a Playbook that uses facts in a Jinja2 template to set different port values for Ubuntu and CentOS.
- Write a Playbook that installs Apache using a Galaxy role and configures it using a template.
- Write a Playbook that installs MySQL using a Galaxy role and configures users using the user module.
- Write a Playbook that uses a module from the community.general collection.
- Write a Playbook that installs Nginx, configures it using a template, and enables the service.
- Create a custom Ansible module in Python that prints “Hello Custom Module”.
- Create a custom Ansible module in PowerShell that prints system information on a Windows node.
- Write a complete Playbook: Install Apache → Copy template index.html → Create web user → Start Apache → Verify service.