Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Issue #146: Add PostgreSQL support.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Oct 1, 2016
1 parent c40e805 commit 83c7fde
Show file tree
Hide file tree
Showing 39 changed files with 726 additions and 14 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ env:
IP: 192.168.88.88
DRUPALVM_DIR: /var/www/drupalvm
matrix:
# Defaults - Ubuntu 16.04.
- distro: ubuntu1604
init: /sbin/init
run_opts: "--privileged"
# Nginx and Drush make file test - Ubuntu 16.04.
- distro: ubuntu1604
init: /sbin/init
run_opts: "--privileged"
local_config: tests/ubuntu-16-nginx.config.yml
config_dir: /var/www/drupalvm/config
# PostgreSQL - Ubuntu 16.04.
- distro: ubuntu1604
init: /sbin/init
run_opts: "--privileged"
local_config: tests/ubuntu-16-postgres.config.yml
config_dir: /var/www/drupalvm/config
# Defaults - CentOS 7.
- distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It will install the following on an Ubuntu 16.04 (by default) linux VM:

- Apache 2.4.x (or Nginx 1.x)
- PHP 7.0.x (configurable)
- MySQL 5.7.x
- MySQL 5.7.x (or PostgreSQL 9.x)
- Drush (configurable)
- Drupal 7.x, or 8.x.x (configurable)
- Optional:
Expand Down
29 changes: 20 additions & 9 deletions default.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ force_ansible_local: false
# The web server software to use. Can be either 'apache' or 'nginx'.
drupalvm_webserver: apache

# The database system to use. Can be either 'mysql' or 'pgsql'.
drupalvm_database: mysql

# Set this to 'false' if you are using a different site deployment strategy and
# would like to configure 'vagrant_synced_folders' and 'apache_vhosts' manually.
build_makefile: false
Expand All @@ -68,9 +71,9 @@ install_site: true

# Required Drupal settings.
drupal_core_path: "{{ drupal_composer_install_dir }}/web"
drupal_mysql_user: drupal
drupal_mysql_password: drupal
drupal_mysql_database: drupal
drupal_db_user: drupal
drupal_db_password: drupal
drupal_db_name: drupal

# Settings for installing a Drupal site if 'install_site:' is 'true'.
drupal_major_version: 8
Expand Down Expand Up @@ -161,18 +164,26 @@ nginx_hosts:
nginx_remove_default_vhost: true
nginx_ppa_use: true

# MySQL Databases and users. If 'install_site' is 'true', first database will
# be used for the site.
# MySQL databases and users.
mysql_databases:
- name: "{{ drupal_mysql_database }}"
- name: "{{ drupal_db_name }}"
encoding: utf8mb4
collation: utf8mb4_general_ci

mysql_users:
- name: "{{ drupal_mysql_user }}"
- name: "{{ drupal_db_user }}"
host: "%"
password: "{{ drupal_mysql_password }}"
priv: "{{ drupal_mysql_database }}.*:ALL"
password: "{{ drupal_db_password }}"
priv: "{{ drupal_db_name }}.*:ALL"

# PostgreSQL databases and users.
postgresql_databases:
- name: "{{ drupal_db_name }}"

postgresql_users:
- name: "{{ drupal_db_user }}"
password: "{{ drupal_db_password }}"
priv: "ALL"

# Comment out any extra utilities you don't want to install. If you don't want
# to install *any* extras, set this value to an empty set, e.g. `[]`.
Expand Down
9 changes: 9 additions & 0 deletions docs/extras/postgresql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Since Drupal VM is built in a modular fashion, you can swap out the database engine and use [PostgreSQL](https://www.postgresql.org/) instead of MySQL (as long as the version of Drupal you're using supports it!).

To switch from MySQL to PostgreSQL, switch the `drupalvm_database` setting in your local `config.yml` to `pgsql`:

```yaml
drupalvm_database: mysql
```
For more PostgreSQL configuration options, see the README included with the [`geerlingguy.postgresql](https://galaxy.ansible.com/geerlingguy/postgresql/) Ansible role.
2 changes: 1 addition & 1 deletion examples/prod/prod.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apache_vhosts:
# Since this will be a publicly-accessible instance of Drupal VM, make sure you
# configure secure passwords, especially for Drupal and MySQL!
drupal_account_pass: admin
drupal_mysql_password: drupal
drupal_db_password: drupal
mysql_root_password: root

# Only install extras that you will need/use on your site, and don't install
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pages:
- 'Use Drupal Console with Drupal VM': 'extras/drupal-console.md'
- 'Use Varnish with Drupal VM': 'extras/varnish.md'
- 'Use MariaDB instead of MySQL': 'extras/mariadb.md'
- 'Use PostgreSQL instead of MySQL': 'extras/postgresql.md'
- 'Use Node.js and NPM': 'extras/nodejs.md'
- 'Use SSL vhosts with Apache': 'extras/ssl.md'
- 'View Logs with Pimp my Log': 'extras/pimpmylog.md'
Expand Down
6 changes: 4 additions & 2 deletions provisioning/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@
- { role: geerlingguy.apache, when: drupalvm_webserver == 'apache' }
- { role: geerlingguy.apache-php-fpm, when: drupalvm_webserver == 'apache' }
- { role: geerlingguy.nginx, when: drupalvm_webserver == 'nginx' }
- geerlingguy.mysql
- geerlingguy.php
- geerlingguy.php-pecl
- geerlingguy.php-mysql
- geerlingguy.composer
- geerlingguy.drush
- { role: geerlingguy.mysql, when: drupalvm_database == 'mysql' }
- { role: geerlingguy.php-mysql, when: drupalvm_database == 'mysql' }
- { role: geerlingguy.postgresql, when: drupalvm_database == 'pgsql' }
- { role: geerlingguy.php-pgsql, when: drupalvm_database == 'pgsql' }

# Conditionally-installed roles.
- { role: geerlingguy.drupal-console, when: 'drupal_major_version > 7 and "drupalconsole" in installed_extras' }
Expand Down
4 changes: 4 additions & 0 deletions provisioning/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
version: 2.0.1
- src: geerlingguy.php-pecl
version: 1.2.1
- src: geerlingguy.php-pgsql
version: 1.0.0
- src: geerlingguy.php-redis
version: 3.0.0
- src: geerlingguy.php-xdebug
Expand All @@ -55,6 +57,8 @@
version: 1.0.2
- src: geerlingguy.postfix
version: 1.1.0
- src: geerlingguy.postgresql
version: 1.0.0
- src: geerlingguy.redis
version: 1.2.0
- src: geerlingguy.repo-remi
Expand Down
46 changes: 46 additions & 0 deletions provisioning/roles/geerlingguy.php-pgsql/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
services: docker

env:
- distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: ubuntu1604
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"

before_install:
# Pull container.
- 'docker pull geerlingguy/docker-${distro}-ansible:latest'

script:
- container_id=$(mktemp)
# Run container in detached state.
- 'docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'

# Install dependencies.
- 'docker exec "$(cat ${container_id})" ansible-galaxy install -r /etc/ansible/roles/role_under_test/tests/requirements.yml'

# Ansible syntax check.
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'

# Test role.
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'

# Test role idempotence.
- idempotence=$(mktemp)
- docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml | tee -a ${idempotence}
- >
tail ${idempotence}
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Ensure PHP PostgreSQL support is enabled.
- docker exec --tty "$(cat ${container_id})" env TERM=xterm php -i | grep 'PostgreSQL Support => enabled'

after_failure:
- docker exec --tty "$(cat ${container_id})" env TERM=xterm php -i

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
42 changes: 42 additions & 0 deletions provisioning/roles/geerlingguy.php-pgsql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Ansible Role: PHP-PostgreSQL

[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-php-pgsql.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-php-pgsql)

Installs PHP [PostgreSQL](https://www.postgresql.org/) support on Linux.

## Requirements

None.

## Role Variables

Available variables are listed below, along with default values (see `defaults/main.yml`):

php_enablerepo: ""

(RedHat/CentOS only) If you have enabled any additional repositories (might I suggest geerlingguy.repo-epel or geerlingguy.repo-remi), those repositories can be listed under this variable (e.g. `remi,epel`). This can allow you to install later versions of PHP packages.

php_pgsql_package: php-pgsql # RedHat
php_pgsql_package: php7.0-pgsql # Debian

The PHP PostgreSQL package to install via apt/yum. This should only be overridden if you need to install a unique/special package for PostgreSQL support, as in the case of using software collections on Enterprise Linux.

## Dependencies

- geerlingguy.php

## Example Playbook

- hosts: webservers
roles:
- geerlingguy.postgresql
- geerlingguy.php
- geerlingguy.php-pgsql

## License

MIT / BSD

## Author Information

This role was created in 2016 by [Jeff Geerling](http://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
3 changes: 3 additions & 0 deletions provisioning/roles/geerlingguy.php-pgsql/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Pass in a comma-separated list of repos to use (e.g. "remi,epel").
php_enablerepo: ""
26 changes: 26 additions & 0 deletions provisioning/roles/geerlingguy.php-pgsql/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
dependencies:
- geerlingguy.php

galaxy_info:
author: geerlingguy
description: PHP PostgreSQL support for Linux.
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 1.8
platforms:
- name: EL
versions:
- all
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all
galaxy_tags:
- database
- web
- postgres
- php
- pgsql
29 changes: 29 additions & 0 deletions provisioning/roles/geerlingguy.php-pgsql/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# Variable setup.
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"

- name: Define php_pgsql_package.
set_fact:
php_pgsql_package: "{{ __php_pgsql_package }}"
when: php_pgsql_package is not defined

# Installation.
- name: Install PHP PostgreSQL dependencies (RedHat).
yum:
name: "{{ php_pgsql_package }}"
state: present
enablerepo: "{{ php_enablerepo }}"
notify:
- restart webserver
- restart php-fpm
when: ansible_os_family == 'RedHat'

- name: Install PHP PostgreSQL dependencies (Debian).
apt:
name: "{{ php_pgsql_package }}"
state: present
notify:
- restart webserver
- restart php-fpm
when: ansible_os_family == 'Debian'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- src: geerlingguy.repo-remi
- src: geerlingguy.apache
- src: geerlingguy.postgresql
- src: geerlingguy.php
18 changes: 18 additions & 0 deletions provisioning/roles/geerlingguy.php-pgsql/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- hosts: all

vars:
php_enablerepo: "remi,remi-php70"

pre_tasks:
- name: Update apt cache.
apt: update_cache=yes
when: ansible_os_family == 'Debian'

roles:
- role: geerlingguy.repo-remi
when: ansible_os_family == 'RedHat'
- geerlingguy.apache
- geerlingguy.postgresql
- geerlingguy.php
- role_under_test
2 changes: 2 additions & 0 deletions provisioning/roles/geerlingguy.php-pgsql/vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
__php_pgsql_package: php7.0-pgsql
2 changes: 2 additions & 0 deletions provisioning/roles/geerlingguy.php-pgsql/vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
__php_pgsql_package: php-pgsql
Loading

0 comments on commit 83c7fde

Please sign in to comment.