bmeme.drupal
Ansible Role: Drupal
This role helps you create, install, and build a Drupal project.
This is the first Ansible Role released by Bmeme and is actively used in our Drupal development. It was inspired by great roles we’ve previously used, such as:
Requirements
To use this role, you will need a basic LAMP/LEMP stack:
- A web server (preferably Apache or Nginx)
- A MySQL/PostgreSQL database
- PHP interpreter (version 7.x or newer)
- Composer (we recommend using
geerlingguy.composer
)
You will also need Drush, which this role will provide for your Drupal project.
Dependencies
community.mysql
collectioncommunity.general
collection
Installation
This Ansible role is available via Ansible Galaxy. To install it, use the command:
$ ansible-galaxy install bmeme.drupal
Update
To update the role, use the --force parameter like this:
$ ansible-galaxy install --force bmeme.drupal
Pre-release Version
There’s a pre-release version (0.5-beta1) that has a different workflow and variable structure. This version is deprecated and should not be used.
Role Variables
Here are the available variables you can customize:
Variable Name | Description | Default |
---|---|---|
drupal_project_dir |
Path where the Drupal project will be installed | /var/www/html |
drupal_project_owner |
User who owns the project | www-data |
drupal_project_group |
Group that owns the project | www-data |
drupal_project_composer_project |
Composer project to use for installing Drupal | drupal/recommended-project |
drupal_project_web_root |
Directory where the Drupal core is stored. This may vary by Drupal version. | web |
drupal_site_name |
Name of your Drupal site | Your new Drupal instance |
drupal_site_mail |
Email for your Drupal site | [email protected] |
drupal_site_lang |
Default language for your Drupal site | en |
drupal_account_mail |
Email for the Drupal account | same as drupal_site_mail |
drupal_account_name |
Name for the Drupal account | admin |
drupal_account_pass |
Password for the Drupal account | admin |
drupal_db_schema |
Database schema to use (options: mysql or pgsql ) |
mysql |
drupal_db_name |
Name of the database | drupal |
drupal_db_user |
Database user | drupal |
drupal_db_pass |
Password for the database user | drupal |
drupal_db_host |
Database host address | 127.0.0.1 |
drupal_db_port |
Database host port | 3306 |
drupal_profile |
Installation profile for Drupal. Refer to this bug | minimal |
drupal_composer_nodev |
Composer "nodev" option (true or false) | false |
drupal_composer_prefer_dist |
Composer "prefer-dist" option (true or false) | false |
drupal_composer_scaffold_nonamespace |
Use Composer without namespace for installing Drupal Scaffold (true or false) | false |
Workflow
This role automates three primary tasks:
- create: Use composer to create a new Drupal project. If a project already exists, this task is skipped.
- install: Install the Drupal instance using Drush. If the installation already exists, this task is skipped, and configurations are exported at the end.
- build: Build the Drupal instance using existing exported configurations. If the configurations do not exist, this task is skipped.
If starting from scratch, only the create and install tasks will be executed.
Hooks
You can add custom tasks at specific points using these hooks:
drupal_before_create
: Runs before the create tasks. Skipped if a Drupal project already exists.drupal_after_create
: Runs after the create tasks. Skipped if a Drupal project already exists.drupal_before_install
: Runs before the install tasks. Skipped if configurations are already present.drupal_after_install
: Runs after the install tasks. Skipped if configurations are already present.drupal_before_build
: Runs before the build tasks. Skipped if configurations are not available.drupal_after_build
: Runs after the build tasks. Skipped if configurations are not available.
Bmeme Work Process
Bmeme uses this role to automate the creation, installation, and building of Drupal projects during development. We work with Docker for our development environment, both locally and on remote test servers. The role operates inside our Docker images php
found here. The same images are used for the role's molecule testing.
Dependencies
N/A
Example Playbook
- hosts: webserver
vars_files:
- vars/main.yml
roles:
- geerlingguy.apache
- geerlingguy.mysql
- geerlingguy.php-versions
- geerlingguy.php
- geerlingguy.php-mysql
- geerlingguy.composer
- bmeme.drupal
In vars/main.yml
:
drupal_project_dir: /path/to/my/project
drupal_site_name: My Awesome Drupal instance
drupal_after_build: "tasks/my-after-build-tasks.yml"
To install a specific Drupal distribution (like Lightning):
- hosts: webserver
vars_files:
- vars/main.yml
roles:
- geerlingguy.apache
- geerlingguy.mysql
- geerlingguy.php-versions
- geerlingguy.php
- geerlingguy.php-mysql
- geerlingguy.composer
- bmeme.drupal
drupal_project_composer_project: "acquia/lightning-project:8.8.1"
License
MIT/BSD
Author Information
This role was created in 2020 by Bmeme.
Creates a Drupal project via composer, install it and re-build it by configs
ansible-galaxy install bmeme.drupal