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

Refactor tasks into shim roles #1327

Merged
merged 13 commits into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions default.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,5 @@ selenium_version: 2.53.0
# Other configuration.
dashboard_install_dir: /var/www/dashboard
known_hosts_path: ~/.ssh/known_hosts
hostname_fqdn: "{{ vagrant_hostname }}"
ssh_home: "{{ drupal_core_path }}"
45 changes: 12 additions & 33 deletions provisioning/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,10 @@
- ../default.config.yml

pre_tasks:
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
- include: tasks/config.yml
tags: ['always']

- name: Define config_dir.
set_fact:
config_dir: "{{ playbook_dir }}/.."
when: config_dir is not defined
tags: ['always']

- name: Include optional configuration files.
include_vars: "{{ item }}"
with_fileglob:
- "{{ config_dir }}/config.yml"
- "{{ config_dir }}/local.config.yml"
- "{{ config_dir }}/secrets.yml"
- "{{ config_dir }}/{{ lookup('env', 'DRUPALVM_ENV')|default(drupalvm_env, true)|default(ansible_env.DRUPALVM_ENV)|default(omit) }}.config.yml"
tags: ['always']

- include: tasks/hostname.yml
tags: ['php', 'drupal']

- include: tasks/init-debian.yml
when: ansible_os_family == 'Debian'
tags: ['php']
static: no
- include: tasks/init-redhat.yml
when: ansible_os_family == 'RedHat'
tags: ['php']
- include: "tasks/init-{{ ansible_os_family }}.yml"
static: no

- name: Run configured pre-provision shell scripts.
Expand All @@ -50,17 +25,18 @@
- "{{ pre_provision_tasks_dir|default(omit) }}"

- include: tasks/php.yml
tags: ['php']

roles:
# Essential roles.
- { role: geerlingguy.repo-remi, when: ansible_os_family == 'RedHat', tags: ['webserver, php'] }
- { role: geerlingguy.repo-remi, when: ansible_os_family == 'RedHat', tags: ['webserver', 'php'] }
- { role: drupalvm.hostname }
- { role: geerlingguy.firewall }
- { role: geerlingguy.git }
- { role: geerlingguy.postfix }
- { role: geerlingguy.apache, when: drupalvm_webserver == 'apache', tags: ['webserver']}
- { role: geerlingguy.apache-php-fpm, when: drupalvm_webserver == 'apache', tags: ['webserver'] }
- { role: geerlingguy.nginx, when: drupalvm_webserver == 'nginx', tags: ['webserver'] }
- { role: drupalvm.php-versions, tags: ['php', 'xdebug', 'database'] }
- { role: geerlingguy.php, tags: ['php'] }
- { role: geerlingguy.php-pecl, tags: ['php'] }
- { role: geerlingguy.composer }
Expand All @@ -73,24 +49,27 @@
- { role: geerlingguy.drupal-console, when: 'drupal_major_version > 7 and "drupalconsole" in installed_extras' }
- { role: geerlingguy.drush, when: '"drush" in installed_extras' }
- { role: geerlingguy.memcached, when: '"memcached" in installed_extras' }
- { role: geerlingguy.php-memcached, when: '"memcached" in installed_extras' }
- { role: geerlingguy.php-memcached, when: '"memcached" in installed_extras', tags: ['php'] }

- role: geerlingguy.php-tideways
workspace: "/root/php{{ php_version }}"
when: '"tideways" in installed_extras'
tags: ['php']

- role: geerlingguy.php-xdebug
workspace: "/root/php{{ php_version }}"
when: '"xdebug" in installed_extras'
tags: ['xdebug']
tags: ['php', 'xdebug']

- role: geerlingguy.php-xhprof
workspace: "/root/php{{ php_version }}"
when: '"xhprof" in installed_extras'
tags: ['php']

- role: thom8.php-upload-progress
workspace: "/root/php{{ php_version }}"
when: '"upload-progress" in installed_extras'
tags: ['php']

- { role: geerlingguy.blackfire, when: '"blackfire" in installed_extras' }
- { role: geerlingguy.adminer, when: '"adminer" in installed_extras', tags: ['database'] }
Expand All @@ -100,7 +79,7 @@
- { role: franklinkim.newrelic, when: '"newrelic" in installed_extras' }
- { role: geerlingguy.nodejs, when: '"nodejs" in installed_extras' }
- { role: geerlingguy.redis, when: '"redis" in installed_extras' }
- { role: geerlingguy.php-redis, when: '"redis" in installed_extras' }
- { role: geerlingguy.php-redis, when: '"redis" in installed_extras', tags: ['php'] }
- { role: geerlingguy.ruby, when: '"ruby" in installed_extras' }

- role: geerlingguy.java
Expand Down Expand Up @@ -135,7 +114,7 @@

- include: tasks/dashboard.yml
when: dashboard_install_dir is defined and dashboard_install_dir != ''
tags: ['webserver', 'database']
tags: ['webserver', 'database', 'php']

- name: Run configured post-provision shell scripts.
script: "{{ item }}"
Expand Down
47 changes: 47 additions & 0 deletions provisioning/roles/drupalvm.hostname/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Drupal VM hostname Role

This role is a shim to set the hostname and FQDN of Drupal VM.

## Requirements

This role is meant to be run in Drupal VM. Use outside of Drupal VM will likely result in weird things happening.

## Role Variables

Available variables are listed below:

```yaml
hostname_fqdn: "{{ inventory_hostname }}"
```

The fully qualified domain name.

```yaml
hostname_short: "{{ hostname_fqdn|regex_replace('^([^.]+).*$', '\\1') }}"
```

The shortname defaulting to the part up to the first period of the FQDN, without the rest of the domain.

```yaml
hostname_unsafe_writes: "{{ (ansible_virtualization_type == 'docker')|ternary('yes', 'no')|bool }}"
```

Whether to use unsafe writes or atomic operations when updating system files. Defaults to atomic operations on all systems except for docker where mounted files cannot be updated atomically and can only be done in an unsafe manner.

## Dependencies

None.

## Example Playbook

- hosts: drupalvm
roles:
- drupalvm.hostname

## License

MIT / BSD

## Author Information

This role was created in 2017 by [Oskar Schöldström](http://oxy.fi) and [Jeff Geerling](https://www.jeffgeerling.com/) (author of [Ansible for DevOps](https://www.ansiblefordevops.com/)).
5 changes: 5 additions & 0 deletions provisioning/roles/drupalvm.hostname/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
hostname_fqdn: "{{ inventory_hostname }}"
hostname_short: "{{ hostname_fqdn|regex_replace('^([^.]+).*$', '\\1') }}"

hostname_unsafe_writes: "{{ (ansible_virtualization_type == 'docker')|ternary('yes', 'no')|bool }}"
28 changes: 28 additions & 0 deletions provisioning/roles/drupalvm.hostname/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
galaxy_info:
author: Jeff Geerling
description: A role to set the hostname and FQDN on Drupal VM.
company: Midwestern Mac, LLC
issue_tracker_url: https://github.com/geerlingguy/drupal-vm/issues
license: MIT
min_ansible_version: 2.2

platforms:
- name: EL
versions:
- all
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- precise
- raring
- saucy
- trusty
- xenial

galaxy_tags:
- drupal
- vm
- hostname
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
- name: Define fully qualified domain name.
set_fact:
hostname_fqdn: "{{ vagrant_hostname }}"
when: hostname_fqdn is undefined

- name: Define short hostname.
set_fact:
hostname_short: "{{ hostname_fqdn|regex_replace('^([^.]+).*$', '\\1') }}"
when: hostname_short is undefined
---
- name: Configure /etc/mailname (Debian).
copy:
content: "{{ hostname_fqdn }}\n"
dest: /etc/mailname
when: ansible_os_family == 'Debian'

- name: Add hostname to /etc/hosts.
lineinfile:
dest: /etc/hosts
regexp: '.*\t{{ hostname_short }}$'
line: "127.0.0.1\t{{ hostname_fqdn }}\t{{ hostname_short }}"
state: present
unsafe_writes: "{{ (ansible_virtualization_type == 'docker')|ternary('yes', 'no')|bool }}"
unsafe_writes: "{{ hostname_unsafe_writes }}"

- name: Configure hostname.
copy:
content: "{{ (ansible_os_family == 'Debian') | ternary(hostname_short, hostname_fqdn) }}\n"
dest: /etc/hostname
unsafe_writes: "{{ (ansible_virtualization_type == 'docker')|ternary('yes', 'no')|bool }}"
unsafe_writes: "{{ hostname_unsafe_writes }}"
register: set_hostname

- name: Set the hostname for current session.
Expand Down
36 changes: 36 additions & 0 deletions provisioning/roles/drupalvm.php-versions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Drupal VM PHP Versions Role

This role is a shim to configure miscellaneous settings prior to installing PHP inside Drupal VM.

## Requirements

This role is meant to be run in Drupal VM. Use outside of Drupal VM will likely result in weird things happening.

## Role Variables

The role has no default variables, but configures the `geerlingguy.php` role variables according to OS and PHP versions.

```yaml
php_version
```

The PHP version used. This variable does not have a default and thus needs to be set.

## Dependencies

- geerlingguy.php is a soft dependency as the `php_version` variable is required to be set.

## Example Playbook

- hosts: drupalvm
roles:
- drupalvm.php-versions
- geerlingguy.php

## License

MIT / BSD

## Author Information

This role was created in 2017 by [Oskar Schöldström](http://oxy.fi) and [Jeff Geerling](https://www.jeffgeerling.com/) (author of [Ansible for DevOps](https://www.ansiblefordevops.com/)).
28 changes: 28 additions & 0 deletions provisioning/roles/drupalvm.php-versions/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
galaxy_info:
author: Jeff Geerling
description: A role to configure various odds and ends prior to installing PHP in Drupal VM.
company: Midwestern Mac, LLC
issue_tracker_url: https://github.com/geerlingguy/drupal-vm/issues
license: MIT
min_ansible_version: 2.2

platforms:
- name: EL
versions:
- all
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- precise
- raring
- saucy
- trusty
- xenial

galaxy_tags:
- drupal
- vm
- php
13 changes: 13 additions & 0 deletions provisioning/roles/drupalvm.php-versions/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"

# Setup tasks.
- include: "setup-{{ ansible_os_family }}.yml"
static: no

- name: Set the correct XHProf package when PHP 5.6 is used.
set_fact:
xhprof_download_url: https://github.com/phacility/xhprof/archive/master.tar.gz
xhprof_download_folder_name: xhprof-master
when: php_version == '5.6'
Original file line number Diff line number Diff line change
@@ -1,48 +1,17 @@
---
- name: Update apt cache if needed.
apt: update_cache=yes cache_valid_time=86400

- name: Install required dependencies.
apt: "name={{ item }} state=installed"
with_items:
- curl
- python-apt
- python-pycurl
- sudo
- unzip
- make

- name: Configure /etc/mailname.
copy:
content: "{{ hostname_fqdn }}\n"
dest: /etc/mailname

- name: Define php_xhprof_html_dir.
- name: Set the correct opcache filename (Ubuntu).
set_fact:
php_xhprof_html_dir: "/usr/share/php/xhprof_html"
when: php_xhprof_html_dir is not defined

# Ubuntu-specific tasks.
- name: Add repository for Apache 2.4.9+ (Ubuntu 12/14).
apt_repository: repo='ppa:ondrej/apache2'
when: >
(ansible_distribution_release == "precise" or ansible_distribution_release == "trusty") and
ansible_distribution == "Ubuntu"
php_opcache_conf_filename: "10-opcache.ini"
when: ansible_distribution == "Ubuntu"

- name: Add repository for PHP versions (Ubuntu).
apt_repository: repo='ppa:ondrej/php'
when: ansible_distribution == "Ubuntu"
register: php_ondrej_ubuntu_repo

- name: Add repository for PHP 5 compatibility packages (Ubuntu).
apt_repository: repo='ppa:ondrej/php5-compat'
when: php_version == "5.6" and ansible_distribution == "Ubuntu"

- name: Set the correct opcache filename (Ubuntu).
set_fact:
php_opcache_conf_filename: "10-opcache.ini"
when: ansible_distribution == "Ubuntu"

# Debian-specific tasks.
- name: Add dependencies for PHP versions (Debian).
apt:
Expand Down Expand Up @@ -81,26 +50,3 @@
- "{{ php_packages|regex_replace('php' + php_version, 'php5.6') }}"
- "{{ php_packages|regex_replace('php' + php_version, 'php7.0') }}"
- "{{ php_packages|regex_replace('php' + php_version, 'php7.1') }}"
register: php_purge

- name: Purge PHP packages installed by default.
apt:
name: "{{ item }}"
state: absent
purge: yes
force: yes
when: >
php_purge.changed or
php_ondrej_ubuntu_repo.changed or
php_ondrej_debian_repo.changed
with_items:
- php-common

- name: Purge PHP modules directory.
file:
path: "{{ item }}"
state: absent
when: php_purge.changed
with_items:
- "/usr/lib/php5/modules"
- "/usr/lib/php/modules"
Loading