How to Create Drupal Role with Ansible Playbook

In this article, you will get some information on the creation of Drupal role for further running of Ansible playbook.

Drupal Role

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

mkdir -p roles/drupal/tasks
nano roles/drupal/tasks/main.yaml
- name: clone Drush repository
version: "9.3.0"
dest: /opt/drush
- name: install mysql client
package: name=mysql-client state=present
- name: create the Drupal install directory
path: "{{ drupal_site_path }}"
state: directory
- name: clone Drupal repository
version: "{{ drupal_version }}"
dest: "{{ drupal_site_path }}"
- name: install Drupal dependencies with Composer
shell: composer install
chdir: "{{ drupal_site_path }}"
creates: "{{ drupal_site_path }}/vendor/autoload.php"
- 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 }}
chdir: "{{ drupal_site_path }}"
Finally, set the proper ownership and permissions on Drupal directories and files.
- name: set proper ownership
path: "{{ drupal_site_path }}"
owner: www-data
group: www-data
recurse: yes
- name: set permissions on the settings file
path: "{{ drupal_site_path }}/sites/default/settings.php"
mode: 0744
- name: set permissions on files direcotry
path: "{{ drupal_site_path }}/sites/default/files"
mode: 0777
state: directory
recurse: yes
nano group_vars/all.yaml
# Drupal Variablesdrupal_version: 8.5.3
drupal_site_path: "/var/www/drupal"
drupal_site_name: "My Drupal Site"
drupal_admin_username: admin
drupal_admin_pass: StrongPass

Related Blog Posts

Deploying Drupal 8 using Ansible Playbook: Part 1

Related Market Product

Drupal 7 — CMS powered by MIRI Infotech (LAMP — Ubuntu16)

Related Documentation

[Vulnerability notice] CVE-2017–6923/6924/6925: Multiple high-risk vulnerabilities in Dural

Related Products

Elastic Compute Service

Related Course

Build Your First Personal Website On Alibaba Cloud Using ECS

Original Source

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

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