In this article, you will get some information on the creation of Drupal role for further running of Ansible playbook.
Create a new directory for "drupal" role and subdirectories for tasks.
mkdir -p roles/drupal/tasks
Now, create a new YAML file to write the tasks of "drupal" role.
nano roles/drupal/tasks/main.yaml
The Composer is used to manage the dependencies of a php-based project. Since we will be cloning the Git repository onto the server, we will require Composer to install the dependencies. Notice the "creates" keyword in the arguments. It simply verifies if the said file is created or not. The next task installs the Git.
Now that Git is installed, clone the Drush repository using the "git" module of the Ansible. Drush is a command line tool to install Drupal.
- name: clone Drush repository
git:
repo: https://github.com/drush-ops/drush.git
version: "9.3.0"
dest: /opt/drush
Create a soft link so that the Drush executable is called directly. The "file" module is used to create the soft links. Then install MySQL client. MySQL client is used by Drush to write the Drupal database.
- name: install mysql client
package: name=mysql-client state=present
Create the directory to install Drupal. The "file" module is also used to create the directory.
- name: create the Drupal install directory
file:
path: "{{ drupal_site_path }}"
state: directory
Clone the Drupal repository.
- name: clone Drupal repository
git:
repo: http://git.drupal.org/project/drupal.git
version: "{{ drupal_version }}"
dest: "{{ drupal_site_path }}"
Install the Drupal dependencies with the Composer.
- name: install Drupal dependencies with Composer
shell: composer install
args:
chdir: "{{ drupal_site_path }}"
creates: "{{ drupal_site_path }}/vendor/autoload.php"
Use Drush executable to install Drupal. We have used Ansible variables for providing the website name and the administrator credentials in the variable file.
- name: install Drupal
shell: drush si -y --site-name="{{ drupal_site_name }}" --account-name={{ drupal_admin_username }} --account-pass="{{ drupal_admin_pass }}" --db-url=mysql://{{ drupal_db_user }}:{{ drupal_db_pass }}@{{ hostvars['db-server']['ansible_default_ipv4']['address'] }}/{{ drupal_db_name }}
args:
chdir: "{{ drupal_site_path }}"
Finally, set the proper ownership and permissions on Drupal directories and files.
- name: set proper ownership
file:
path: "{{ drupal_site_path }}"
owner: www-data
group: www-data
recurse: yes
- name: set permissions on the settings file
file:
path: "{{ drupal_site_path }}/sites/default/settings.php"
mode: 0744
- name: set permissions on files direcotry
file:
path: "{{ drupal_site_path }}/sites/default/files"
mode: 0777
state: directory
recurse: yes
Save the file and exit from the editor. The role for installing the Drupal is also created. Since we have used some variable in the role we have created, let's add them in the global variable file we have created.
Edit the common global variables file.
nano group_vars/all.yaml
Append the following variables at the end of the line.
# Drupal Variables
drupal_version: 8.5.3
drupal_site_path: "/var/www/drupal"
drupal_site_name: "My Drupal Site"
drupal_admin_username: admin
drupal_admin_pass: StrongPass
Our Drupal website is now installed, but we will need to install NGINX web-server to expose the Drupal site to the internet. The last role "nginx" in our Ansible playbook will install the NGINX web-server along with optional SSL support by let's encrypt CA. The user can set the variable to true to generate the let's encrypt certificate in the global variables file. If the SSL cert is generated, then we will configure Drupal to be accessed from the domain name. Else, the Drupal site will be accessed from the IP address of the "web-server" instance.
For how to create Nginx role and run the playbook, please go to this tutorial.
In this three-part tutorial, we will be deploying Drupal 8 using Ansible Playbook on an Alibaba Cloud Elastic Compute Service (ECS) instance. Specifically, we will learn more about writing a modular playbook for Ansible. Each group of tasks will be separated by a specific role in our playbook. In the first part of the tutorial, we will be looking at creating our project and overriding the default Ansible behavior. In the second part of the tutorial, we will write the plays into roles. In the last part of the tutorial, we'll be executing the playbook using Ansible after writing the remaining roles.
In this article, you will get some information on the creation of the roles for our playbook to deploy drupal 8.
Drupal 7 saves time and money by providing a ready-to-run solution.It is secured, well supported and easy to maintain.The system auto-updates itself with security fixes.
Drupal researchers released a security report on August 16, 2017, claiming that several bugs in Drupal 8 have been fixed and security patches have been updated online. According to research, the vulnerabilities affect multiple system components of Drupal 8, including the entity access system, REST API, and some view components.
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 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.
In this short video, we introduced how to quickly deploy a personal website with Alibaba Cloud ECS and Marketplace service.
Alibaba Cloud Showcases Inclusive Technology Ecosystem Empowering Businesses to Grow in Asia Pacific
2,599 posts | 762 followers
FollowAlibaba Clouder - July 12, 2018
Alibaba Clouder - May 29, 2019
Alibaba Clouder - May 31, 2019
Alibaba Clouder - July 12, 2018
Alibaba Clouder - July 12, 2018
Alibaba Clouder - June 3, 2019
2,599 posts | 762 followers
FollowIdentify vulnerabilities and improve security management of Alibaba Cloud WAF and Anti-DDoS and with a fully managed security service
Learn MoreMore Posts by Alibaba Clouder