Ansible END TO END PROJECT - 2 Tier | set up two configuration management server groups

In these project we are set up two configuration management server groups,[Apache & Nginx] when Apache configuration is done, we are installing the java on that Apache server using the Ansible role.

1. Directory Structure

ansible_project/
|-- inventory/
|   |-- production
|-- roles/
|   |-- apache/
|       |-- tasks/
|           |-- main.yml
|       |-- files/
|           |-- index_apache.html
|       |-- handlers/
|           |-- main.yml
|       |-- templates/
|           |-- httpd.conf.j2
|   |-- nginx/
|       |-- tasks/
|           |-- main.yml
|       |-- files/
|           |-- index_nginx.html
|       |-- handlers/
|           |-- main.yml
|   |-- java/
|       |-- tasks/
|           |-- main.yml
|-- playbook.yml
|-- requirements.yml

The Main Project Directory.

This is the root directory for your Ansible project. All other subdirectories and files will be organized under this main directory.

The Inventory Directory.

The inventory directory is where you define your inventory files. The production file is a sample inventory file that lists your server groups.

Create the Roles Directory.

The roles directory is where you organize your roles. Roles are a way to organize your playbooks and make them more modular and reusable.

Create the Apache Role Directory Structure.

In the Apache Folder , task folder present or create then main.yml we need to put there.

roles/apache/tasks/main.yml:

This file contains the tasks specific to the Apache role.

roles/apache/handlers/main.yml:

Handlers are tasks that only run when notified by other tasks.

roles/apache/files/index_apache.html:

This file Contents that, what content we want to show on the Apache server/target machines.

roles/apache/templates/httpd.conf.j2:

This directory contains Jinja2 templates, used for generating the Apache configuration file

Create the NGINX Role Directory Structure.

roles/nginx/tasks/main.yml:

This file contains the tasks specific to the NGINX role.

roles/nginx/handlers/main.yml:

Handlers are tasks that only run when notified by other tasks.

roles/nginx/files/index_nginx.html:

This file Contents that, what content we want to show on the Nginx server/target machines.

Create the Java Role Directory Structure

roles/java/tasks/main.yml:

This file contains the tasks specific to the Java role.

Create the Playbook.

The playbook.yml file is where you define which roles to apply to which server groups. This file is the main entry point for executing your Ansible configuration.

Create the Requirements File.

The requirement.yml file is used to specify external roles that need to be installed using ansible-galaxy.

After running the requirement.yml file , Download the all roles.

Running the playbook.yml

See the Output , which is mention Below.

Last updated