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 MariaDB server and create the database for Drupal on the instance named “db-server”.
  2. Install the PHP 7.2 on the instance “web-server”.
  3. Clone the Drupal 8 and Drush 9 Github repository and install Drupal on the instance “web-server”.
  4. Install the NGINX Web server to host the Drupal site with optional Let’s Encrypt SSL on the instance “web-server”.

Getting Started with Ansible

mkdir ~/drupal-ansible
cd ~/drupal-ansible
nano ansible.cfg
inventory = hosts
host_key_checking = false
private_key_file = ~/.ssh/aliyun.pem
nano hosts
web-server  ansible_ssh_host= ansible_ssh_user=root
db-server ansible_ssh_host= ansible_ssh_user=root
aliyun@ubuntu:~/drupal-ansible$ ansible all -m ping
db-server | SUCCESS => {
"changed": false,
"ping": "pong"
web-server | SUCCESS => {
"changed": false,
"ping": "pong"
cd ~/drupal-ansible
nano playbook.yaml
- hosts: all
gather_facts: true
- name: update and upgrade system packages
upgrade: yes
update_cache: yes
- hosts: db-server
- mariadb
- hosts: web-server
become: true
- php
- drupal
- nginx
  1. mariadb: It will add MariaDB repository into the system and will install the latest version of MariaDB server. Furthermore, it will also install the MySQL client for Python and then it will create the database and the database user for Drupal.
  2. php: This role will add the PPA for PHP 7.2 and then install PHP 7.2 along with the required modules.
  3. drupal: This role will install the latest version of Composer and Git. It will clone the Drush and Drupal repository and will install the dependencies using Composer. Finally, it will install Drupal with the help of Drush.
  4. nginx: This role will install NGINX web-server and configure it to host the Drupal site. If a domain name is provided, it will also install Certbot and generate and install the SSL certificates automatically.
    Once all our systems are updated, we want to proceed to the installation of MariaDB. Notice that on the next block, we have only provided the “db-server” in the hosts. Thus, the tasks in the “mariadb” role will be executed only on the “db-server” host.

Related Blog Posts

Deploying Drupal 8 using Ansible Playbook: Part 2

cd ~/drupal-ansible
mkdir roles

Deploying Drupal 8 using Ansible Playbook: Part 3

Related Market Product

Drupal powered by Websoft9(LAMP | CentOS7.4)

Related Documentation

[Vulnerability notice] SQL injection vulnerability in Drupal

Related Products

Elastic Compute Service

Alibaba Cloud SSL Certificates Service

Related Course

Alibaba Cloud SSL Service Introduction



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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

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