Skip to content

The goal of this project is to automate the creation of two separate environments—production and staging—using Ansible playbooks and its ecosystem.

Notifications You must be signed in to change notification settings

Matthieu-dgl/ansible-php-nginx-mariadb-webapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible Project: Staging & Production

Authors

  • Déglon Matthieu
  • Killyan Batailler

📋 Prerequisites

  • Ansible 2.9 or newer
  • SSH access to Debian-based servers
  • SSH agent with your private key loaded

SSH Setup

Check if your SSH key is added:

ssh-add -l

If not, add it:

ssh-add ~/path/to/your/ssh_key

Install Required Ansible Collections

ansible-galaxy collection install community.general
ansible-galaxy collection install community.mysql
ansible-galaxy collection install -r requirements.yml

🚀 Deployment Commands

Use the provided Makefile commands for quick deployment.

Setup Galaxy Roles

make setup

Full Deployment

make deploy

Deploy Only Web Servers

make deploy.webservers

Deploy Only Database Servers

make deploy.dbservers

Deploy to Specific Environments

make deploy.staging
make deploy.production

Deploy Specific Roles

make deploy.nginx
make deploy.php
make deploy.mariadb
make deploy.webapp

✅ Tests

Check Services

SSH into a server and run:

systemctl status php8.2-fpm
systemctl status mariadb

Test Database

mysql -u root -p
SHOW DATABASES;

Test Web Application

From a browser, visit the IP address of one of the servers.

Ping All Hosts

Run the following from the inventory/ directory:

ansible -i hosts.yml all -m ping

Expected output:

server-01 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}
server-02 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}

📂 Project Structure

.
├── Makefile                    # Installation and deployment commands
├── requirements.yml            # List of Galaxy roles (empty for now)
├── inventory/
│   └── hosts.yml               # Host inventory (staging & production)
├── roles/                      # Ansible roles
│   ├── nginx/
│   │   ├── tasks/main.yml      # NGINX installation and configuration
│   │   ├── handlers/main.yml   # Handler for NGINX reload
│   │   └── templates/
│   │       └── nginx.conf.j2   # NGINX site template
│   ├── php/
│   │   ├── tasks/main.yml      # PHP-FPM installation and configuration
│   │   └── handlers/main.yml   # Handler for PHP-FPM restart
│   ├── mariadb/
│   │   └── tasks/main.yml      # MariaDB installation, securing, DB/user creation
│   └── webapp/
│       ├── tasks/main.yml      # PHP app deployment + connection template
│       ├── files/index.php     # Simple Hello World PHP
│       └── templates/
│           └── db_connect.php.j2  # DB connection test script template
├── playbooks/
    └──group_vars/
│    all.yml                 # Common variables
│   ├── staging/
│   │   ├── php.yml             # PHP limits for staging
│   │   ├── db.yml              # User/database names for staging
│   │   └── vault.yml           # Encrypted variables for staging (DB passwords)
│   └── production/
│       ├── php.yml             # PHP limits for production
│       ├── db.yml              # User/database names for production
│       └── vault.yml           # Encrypted variables for production (DB passwords)
│   ├── main.yml                # Main playbook (all services)
│   ├── webservers.yml          # Web-only playbook
│   └── dbservers.yml           # DB-only playbook
└── README.md                   # Project documentation

🛠 Technologies Used

  • Ansible
  • Nginx
  • PHP 8.2
  • MariaDB
  • Debian

📝 Documentation and Comments Assisted by AI

The documentation and comments have been written with the assistance of artificial intelligence, Claude.

📄 License

This project is licensed under the MIT License.

About

The goal of this project is to automate the creation of two separate environments—production and staging—using Ansible playbooks and its ecosystem.

Resources

Stars

Watchers

Forks

Packages

No packages published