Community Blog How to Deploy Drupal 8 with Ansible Playbook

How to Deploy Drupal 8 with Ansible Playbook

In this article, you will get some information on the creation of the roles for our playbook to deploy drupal 8.

Create a new directory to add the roles in our Ansible playbook by running:

cd ~/drupal-ansible
mkdir roles

Installing MariaDB Role

Create a new directory for "mariadb" role and subdirectories for tasks, handlers, and templates.

mkdir -p roles/mariadb/{tasks,handlers,templates}

Now, create a new YAML file to write the tasks of "mariadb" role.

nano roles/mariadb/tasks/main.yaml

There are several tasks which we will write into the tasks file. We will go through each task to know more about what it does. We will also see the uses of different modules of Ansible.

Note: All the tasks provided below are part of the "main.yaml" file of "drupal" role. Copy and paste the tasks serially until you are instructed to close the file. Tasks are divided in such manner just to explain them. You can click here to check how the whole file should look.

By default, MariaDB listens to the localhost addresses only. In our scenario, we are using one server to host the database server and the other one will be used for installing Drupal. We will need to modify the MariaDB configuration so that it can listen to all address. In our case, the ECS server running Drupal will make queries to the database server instance. The below task will find the line starting with bind-address in the MySQL configuration file /etc/mysql/my.cnf. Upon matching, it will take the backup of the file and will replace the whole line with bind-address = It will then notify the handler to run the job named with restart mariadb.

Finally, create the database for Drupal and also create a new database user having all the privileges over the database we have created.

- 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'] }}

Notice the variable hostvars'web-server'['address'] in the last task. The variable will result in the private IP address of instance named "web-server" which is the instance on which we will install Drupal. This will make sure that our database can be used only from that instance.

Populate the file with the variables we have used in "mariadb" role.

# mariadb role variables

mysql_root_pass: VeryStrongPassword
drupal_db_user: drupal-data
drupal_db_name: drupal-user
drupal_db_pass: StrongPass

For details, please go to this tutorial.

Related Blog Posts

How to Create Ansible playbook for Deploying Drupal 8

In this article, you will get some information on the basics of the Ansible and how Ansible playbook is created.

This tutorial assumes that you have already created both the instance and configured SSH key-based authentication on the instances with the same key. Here are the goals which we will accomplish using Ansible:

  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".

Deploying Drupal 8 using Ansible Playbook: Part 3

In previous tutorials of this series, we have created our playbook file and two of the four roles. In the first part of the tutorial, we looked at creating our project and overriding the default Ansible behavior. In the second part of the tutorial, we have written the plays into roles.

In this final part of the tutorial series, we will create the two remaining roles. Once the playbook is created, we will run the playbook using Ansible.

Related Market Product

Drupal 8 powered by Miri Infotech(LAMP&UBUNTU 16)

It is equipped with a potent blend of features and can support a variety of websites ranging from personal blogs to corporate brochures to large community-driven websites.

Related Documentation

[Vulnerability notice] CVE-2017-6920: Remote code execution vulnerability in Drupal

On June 21, 2017, Drupal officially released a vulnerability numbered CVE-2017-6920, which was rated Critical. The remote code execution vulnerability results from incorrect processing of DrupalCore’s YAML parser. It affects 8.x DrupalCore.

Related Products

Elastic Compute Service

Alibaba Cloud Elastic Compute Service (ECS) provides fast memory and the latest Intel CPUs to help you to power your cloud applications and achieve faster results with low latency. All ECS instances come with Anti-DDoS protection to safeguard your data and applications from DDoS and Trojan attacks.

Alibaba Cloud SSL Certificates Service

Alibaba Cloud SSL Certificates Service allows customers to directly apply, purchase and manage SSL certificates on Alibaba Cloud. This service is offered in cooperation with qualified certificate authorities. From this platform, customers can select the expected certificate authority and its certificate products to enjoy full-site HTTPS security solutions.

Related Course

ACT81002 Alibaba Cloud Technical Operations

The "Alibaba Cloud Technical Operations" course is designed to provide Developers, Technical Operators, Solution Achitecturing Engineers with deployment and management skills for Alibaba Cloud basic products including ECS, OSS, SLB, RDS etc. Moreover, it includes intuitive online labs led by experienced instructors to help you obtain direct hands-on experience on those products's configration and operations.

0 0 0
Share on

Alibaba Clouder

2,626 posts | 711 followers

You may also like