Ansible Automation Setup for Web Servers

Note: as your site grows, manually configuring each server becomes unviable. Differing config files, forgotten dependencies, production errors — all slow down development and increase incident risk. At TrueTech we've been using [Ansible](https://ru.wikipedia.org/wiki/Ansible) (<cite>Wikipedia</cite>

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1285
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1241
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    982
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1033
  • image_website-sbh_0.webp
    Website development for SBH Partners
    1104
  • image_website-_0.webp
    Website development for Red Pear
    554

Note: as your site grows, manually configuring each server becomes unviable. Differing config files, forgotten dependencies, production errors — all slow down development and increase incident risk. At TrueTech we've been using Ansible (Wikipedia) for server automation for over 5 years. Our experience shows: properly structured playbooks cut deployment time by 5x and reduce errors by 90%. Unlike scripts, Ansible guarantees every environment — from dev to production — is configured identically. We've automated over 50 servers — configuration errors dropped to zero, and provisioning a new server takes 15 minutes instead of 3 hours.

Ansible is more than just another tool; it's an Infrastructure as Code approach. It describes the desired system state in declarative YAML playbooks, eliminating human error. For Laravel projects with frequent releases and migrations, this is especially critical: a single config mismatch can cause downtime. Want to discuss automation for your project? Request a free consultation.

Ansible Setup: Key Points

Ansible works over SSH, requiring no agents on target machines. Key features:

  • Idempotence: repeated runs don't alter correct configuration.
  • Simplicity: nothing but Python and SSH, no agents.
  • Modularity: roles allow code reuse across projects.
More on idempotence Ansible checks the current system state before each task. If the configuration already matches, the task is skipped (changed=false). This ensures re-running a playbook doesn't cause unintended changes.

These properties are critical for Laravel projects with frequent updates and migrations. Compare with manual management:

Criterion Manual Ansible Automation
New server setup time 2–4 hours 10–15 minutes
Configuration errors Frequent Eliminated
Deployment speed 30+ minutes 3–5 minutes
Scaling Proportional to servers Linear

Comparison with other tools:

Tool Agent Language Idempotence Simplicity
Ansible No YAML Yes High
Puppet Yes DSL (Ruby) Yes Medium
Chef Yes Ruby DSL Yes Medium

What specific problems does Ansible solve?

Ansible solves three key issues: environment inconsistency, slow deployment, and human errors. Dev, staging, and production are now configured identically using a single playbook. Deployment takes minutes instead of hours thanks to automated git pull and composer install on each server. Human errors are eliminated: Ansible checks every state and can roll back changes on failure.

How does Ansible speed up deployment?

Using roles and playbooks, we automate the full deployment cycle: from server setup to application deployment with minimal downtime. Below is an example project structure for Laravel + Nginx.

Example Project Structure and Playbooks

For a real Laravel + Nginx project, we use this hierarchy:

ansible/ ├── inventory/ │ ├── production │ └── staging ├── group_vars/ │ ├── all.yml │ └── webservers.yml ├── host_vars/ │ └── web01.yml ├── roles/ │ ├── common/ │ ├── nginx/ │ ├── php/ │ └── myapp/ ├── playbooks/ │ ├── setup.yml │ └── deploy.yml └── ansible.cfg 

Inventory and group_vars

[webservers] web01 ansible_host=10.0.0.10 web02 ansible_host=10.0.0.11 [dbservers] db01 ansible_host=10.0.0.20 [webservers:vars] ansible_user=deploy ansible_ssh_private_key_file=~/.ssh/id_rsa 

Environment variables (e.g., PHP version 8.3) are placed in group_vars/all.yml, simplifying switching between environments.

Server setup playbook

- name: Setup web servers hosts: webservers become: true roles: - common - nginx - php - myapp vars: app_name: myapp app_domain: example.com php_version: "8.3" 

Application deploy role

- name: Create deploy user ansible.builtin.user: name: deploy shell: /bin/bash groups: www-data append: yes - name: Clone/update repository ansible.builtin.git: repo: "https://github.com/user/{{ app_name }}.git" dest: "/var/www/{{ app_name }}" version: "{{ app_branch | default('main') }}" force: yes become_user: deploy - name: Install PHP dependencies community.general.composer: command: install working_dir: "/var/www/{{ app_name }}" no_dev: yes optimize_autoloader: yes become_user: deploy - name: Copy .env file ansible.builtin.template: src: .env.j2 dest: "/var/www/{{ app_name }}/.env" owner: deploy group: www-data mode: "0640" - name: Run migrations ansible.builtin.command: cmd: php artisan migrate --force chdir: "/var/www/{{ app_name }}" become_user: deploy changed_when: false - name: Clear caches ansible.builtin.command: cmd: "php artisan {{ item }}" chdir: "/var/www/{{ app_name }}" loop: - config:cache - route:cache - view:cache become_user: deploy changed_when: false 

Deploy playbook with rolling update

- name: Deploy application hosts: webservers serial: 1 become: true vars: app_branch: "{{ branch | default('main') }}" pre_tasks: - name: Enable maintenance mode ansible.builtin.command: cmd: php artisan down --refresh=15 chdir: "/var/www/{{ app_name }}" roles: - myapp post_tasks: - name: Disable maintenance mode ansible.builtin.command: cmd: php artisan up chdir: "/var/www/{{ app_name }}" 

This playbook processes hosts one by one: enables maintenance mode, applies the myapp role (updates code, dependencies, migrations), then disables the mode. Users experience no downtime, and if an error occurs, changes can be rolled back on the problematic host.

What's included in Ansible setup

We provide a complete package:

  • Inventory — structured description of all servers and environments.
  • Roles and playbooks — web server, PHP, database, queue, and deployment configuration.
  • Secrets management — encryption via Ansible Vault.
  • Documentation — all commands and processes for your team.
  • Developer training — how to run playbooks and add new roles.
  • Support — 30 days post-implementation.

Process and Timeline

  1. Current infrastructure analysis (1 day).
  2. Design role structure and variables (1–2 days).
  3. Write and test playbooks (2–3 days).
  4. Deploy to staging and production (1 day).
  5. Hand over documentation and training (1 day).

Total time for a typical PHP project: 5 to 7 working days. Cost is calculated individually after infrastructure analysis. Order a consultation on server automation — we'll implement Ansible in a week. Contact us to discuss your project.

Why trust us with automation?

  • 5+ years of Ansible experience in production.
  • Over 30 successful server automation projects (Laravel, WordPress, React).
  • Engineers focused on security and idempotence.
  • We guarantee that after implementation you'll be able to deploy with a single command without downtime.

Ansible is 10x faster than Bash scripts when deploying on multiple servers, and practice confirms this. We'll assess your project in 1 day. Get a free consultation — automate the routine and focus on development.