Deploying Drupal 8 using Ansible Playbook: Part 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.
  • 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

It is not required to install Ansible on either of the instances which we will manage using the Ansible. However, installation of the Ansible is required on your local workstation from which you are planning to manage the instances. If you want, you can also use a server on Alibaba Cloud to manage other nodes. If you are using a Linux Ubuntu desktop or server, you can follow the instructions on the tutorial, How to install Ansible on Ubuntu 16.04.

aliyun@ubuntu:~$ ansible --version
ansible 2.5.4
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/aliyun/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
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.


In this tutorial, we have learned the basics of the Ansible and how Ansible playbook is created. We have learned to override the Ansible configuration file as well as using a local host file to define the hosts on per project basis. Finally, we created the playbook file which will run all the plays or tasks that we will define in the different roles in the next tutorials.



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

Alibaba Cloud

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