This is a hypothetical implementation of an Ansible project to manage a complex, heterogeneous environment.
environments/
: Contains inventory files for different environments.roles/
: Contains roles for different server types (app1, app2, databases).main.yml
: The main playbook that includes roles based on the target hosts.
-
Navigate to the
environments/dev/
directory and edit theinventory.ini
file to match your actual server IPs/hostnames. -
Run the playbook with the following command:
ansible-playbook -i environments/dev/inventory.ini main.yml
This project also includes sample inventories for multiple environments:
- Development (
dev
) - Pre-Production (
preprod
) - Qualification (
qualification
) - Production (
prod
)
To run the playbook for a specific environment, adjust the -i
flag accordingly:
ansible-playbook -i environments/[env_name]/inventory.ini main.yml
mariadb
: Ensures MariaDB is installed and securely configured.nginx
: Configures NGINX for load balancing and SSL.react
: Sets up React for frontend.nestjs
: Sets up NestJS for backend.
- MariaDB is installed and securely configured on hosts under the
databases
group. - NGINX is installed and configured for load balancing and SSL on hosts under the
load_balancer
group. - React is used for frontend servers under the
frontend
group. - NestJS is used for backend servers under the
backend
group.
The inventory files for each environment (dev
, preprod
, qualification
, prod
) include variables that control these directives.
To run the playbook for a specific environment, use the following command:
ansible-playbook -i environments/[env_name]/inventory.yml main.yml
The main.yml
playbook includes comments, indications, notes, and TODOs for areas you should explore to deepen your understanding of Ansible and DevOps practices. These areas include:
- Variable Scope and Precedence
- Conditionals and Loops
- Templates and Jinja2
- Roles and Include
- Error Handling
- Ansible Vault
- Dynamic Inventory
- Testing
- CI/CD Integration
- Community Resources
Refer to the main.yml
playbook for specific tasks and examples to guide your further study.
- Consideration: Learn how the YAML inventory is structured and how to represent different environments.
- Consideration: Dive into the roles directory to understand the tasks and variables associated with each role.
- Consideration: Always test your playbook in a non-production environment first.
- Consideration: Understand what each task is doing and how to interpret the output.
- Consideration: Try adding your own tasks to the playbook for specific customizations.
- Consideration: Encrypt sensitive data like passwords and API keys using Ansible Vault.
- Consideration: Learn how to use dynamic inventories for environments that change frequently.
- Consideration: Add error handling to your playbook and learn how to debug issues.
- Consideration: Use testing tools like Molecule or Ansible Lint to validate your playbook.
- Consideration: Integrate Ansible into a CI/CD pipeline for automated deployments.
Refer to the main.yml
playbook for specific tasks and examples that align with each step.