Deploying Drupal 8 with Ansible playbook

How to Create Ansible playbook for Deploying Drupal 8


  1. Two Alibaba Cloud ECS instances with Ubuntu 16.04 64-bit installed. You can follow this Quick Start Guide to create the instances. Let’s call the first instance as “web-server” and assume the public IP assigned to the server is “”. We will use this server to install Drupal using Drush on NGINX with PHP 7.2. Similarly, we will call our second server as “db-server” having public IP “”. We will install MariaDB server on this instance to host the Drupal database. Make sure to use SSH Key based authentication rather than password authentication and use the same key for both the instance.
  2. Important: Firewall or Security group rules configured to allow the port “80”, “443” for everyone from the “web-server” instance. For the database server, you will only need to allow access to the private IP address of the “web-server” instance on port “3306”.
  1. Install the PHP 7.2 on the instance “web-server”.
  2. Clone the Drupal 8 and Drush 9 Github repository and install Drupal on the instance “web-server”.
  3. Install the NGINX Web server to host the Drupal site with optional Let’s Encrypt SSL on the instance “web-server”.
- name: create a new database for Drupal
mysql_db: name={{ drupal_db_name }} state=present
- name: create a new database user for Drupal
mysql_user: name={{ drupal_db_user }} password={{ drupal_db_pass }}
priv="{{ drupal_db_name }}.*:ALL" state=present host={{ hostvars['web-server']['ansible_default_ipv4']['address'] }}

Drupal Role

Create a new directory for “drupal” role and subdirectories for tasks.

mkdir -p roles/drupal/tasks
nano roles/drupal/tasks/main.yaml

Related Market Product

Drupal on LAMP CentOS 7.4 Lite

Related Products

Elastic Compute Service

Related Course

Construct a Dynamic Website (Cantonese)

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.