From d3100441de6e57109884df9279736dd56aabcddc Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Fri, 19 May 2017 12:36:36 -0500 Subject: [PATCH] Initial commit, direct port from Drupal VM. --- .gitignore | 2 ++ .travis.yml | 28 +++++++++++++++++++++++ LICENSE | 20 ++++++++++++++++ README.md | 43 ++++++++++++++++++++++++++++++++++ defaults/main.yml | 3 +++ meta/main.yml | 32 ++++++++++++++++++++++++++ tasks/main.yml | 13 +++++++++++ tasks/setup-Debian.yml | 52 ++++++++++++++++++++++++++++++++++++++++++ tasks/setup-RedHat.yml | 12 ++++++++++ tests/README.md | 11 +++++++++ tests/requirements.yml | 3 +++ tests/test.yml | 16 +++++++++++++ vars/Debian.yml | 40 ++++++++++++++++++++++++++++++++ vars/RedHat.yml | 5 ++++ 14 files changed, 280 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 tasks/setup-Debian.yml create mode 100644 tasks/setup-RedHat.yml create mode 100644 tests/README.md create mode 100644 tests/requirements.yml create mode 100644 tests/test.yml create mode 100644 vars/Debian.yml create mode 100644 vars/RedHat.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c9b2377 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.retry +tests/test.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..21804d8 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,28 @@ +--- +services: docker + +env: + - distro: centos7 + - distro: centos6 + - distro: debian8 + - distro: ubuntu1604 + - distro: ubuntu1404 + +script: + # Configure test script so we can run extra tests after playbook is run. + - export container_id=$(date +%s) + - export cleanup=false + + # Download test shim. + - wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/ + - chmod +x ${PWD}/tests/test.sh + + # Run tests. + - ${PWD}/tests/test.sh + + # Run script to test PHP version. + # TODO: Actually test the version. + - 'docker exec ${container_id} env TERM=xterm php -v' + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4275cf3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2017 Jeff Geerling + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d8d597b --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# Ansible Role: PHP Versions + +[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-php-versions.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-php-versions) + +Allows different PHP versions to be installed when using the `geerlingguy.php` role (or a similar role). This role was originally built for [Drupal VM](https://www.drupalvm.com) but was released more generically so others could use an easier mechanism for switching PHP versions. + +## Requirements + +N/A + +## Role Variables + +Available variables are listed below, along with default values (see `defaults/main.yml`): + + php_version: '7.1' + +The PHP version to be installed. Any [currently-supported PHP major version](http://php.net/supported-versions.php) is a valid option (e.g. `5.6`, `7.0`, `7.1`, etc. + +## Dependencies + + - geerlingguy.php is a soft dependency as the `php_version` variable is required to be set. + - geerlingguy.repo-remi, if you're using CentOS or a Red Hat derivative. + +## Example Playbook + + - hosts: webservers + + vars: + php_version: 7.1 + + roles: + - role: geerlingguy.repo-remi + when: ansible_os_family == 'RedHat' + - geerlingguy.php-versions + - geerlingguy.php + +## License + +MIT / BSD + +## Author Information + +This role was created in 2017 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..ea9b337 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,3 @@ +--- +# The PHP version to be installed. +php_version: '7.1' diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..a157a63 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,32 @@ +--- +dependencies: + - geerlingguy.php + +galaxy_info: + author: geerlingguy + description: Allows different PHP versions to be installed. + company: "Midwestern Mac, LLC" + license: "license (BSD, MIT)" + issue_tracker_url: https://github.com/geerlingguy/drupal-vm/issues + min_ansible_version: 2.2 + platforms: + - name: EL + versions: + - all + - name: Debian + versions: + - all + - name: Ubuntu + versions: + - precise + - raring + - saucy + - trusty + - xenial + galaxy_tags: + - php + - web + - drupal + - vm + - magento + - wordpress diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..006adbd --- /dev/null +++ b/tasks/main.yml @@ -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' diff --git a/tasks/setup-Debian.yml b/tasks/setup-Debian.yml new file mode 100644 index 0000000..4e6d73d --- /dev/null +++ b/tasks/setup-Debian.yml @@ -0,0 +1,52 @@ +--- +- name: Set the correct opcache filename (Ubuntu). + set_fact: + 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" + +- 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" + +# Debian-specific tasks. +- name: Add dependencies for PHP versions (Debian). + apt: + name: "{{ item }}" + with_items: + - apt-transport-https + - ca-certificates + when: ansible_distribution == "Debian" + +- name: Add Ondrej Sury's apt key (Debian). + apt_key: + url: https://packages.sury.org/php/apt.gpg + state: present + when: ansible_distribution == "Debian" + +- name: Add Ondrej Sury's repo (Debian). + apt_repository: + repo: "deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main" + state: present + register: php_ondrej_debian_repo + when: ansible_distribution == "Debian" + +- name: Update apt caches after repo is added (Debian). + apt: update_cache=yes + when: php_ondrej_debian_repo.changed and (ansible_distribution == "Debian") + +# PHP package purges. +- name: Purge PHP version packages. + apt: + name: "{{ item }}" + state: absent + purge: yes + force: yes + when: "'php' + php_version not in item" + with_flattened: + - "{{ 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') }}" diff --git a/tasks/setup-RedHat.yml b/tasks/setup-RedHat.yml new file mode 100644 index 0000000..773e53f --- /dev/null +++ b/tasks/setup-RedHat.yml @@ -0,0 +1,12 @@ +--- +- name: Enable remi repo for PHP 5.6. + set_fact: php_enablerepo="remi,remi-php56" + when: php_version == "5.6" + +- name: Enable remi repo for PHP 7.0. + set_fact: php_enablerepo="remi,remi-php70" + when: php_version == "7.0" + +- name: Enable remi repo for PHP 7.1. + set_fact: php_enablerepo="remi,remi-php71" + when: php_version == "7.1" diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..6fb2117 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,11 @@ +# Ansible Role tests + +To run the test playbook(s) in this directory: + + 1. Install and start Docker. + 1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`: + - `wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/` + 1. Make the test shim executable: `chmod +x tests/test.sh`. + 1. Run (from the role root directory) `distro=[distro] playbook=[playbook] ./tests/test.sh` + +If you don't want the container to be automatically deleted after the test playbook is run, add the following environment variables: `cleanup=false container_id=$(date +%s)` diff --git a/tests/requirements.yml b/tests/requirements.yml new file mode 100644 index 0000000..80e765f --- /dev/null +++ b/tests/requirements.yml @@ -0,0 +1,3 @@ +--- +- src: geerlingguy.repo-remi +- src: geerlingguy.php diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..0740bbf --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,16 @@ +--- +- hosts: all + + vars: + php_enable_webserver: false + + pre_tasks: + - name: Update apt cache. + apt: update_cache=yes cache_valid_time=600 + when: ansible_os_family == 'Debian' + + roles: + - role: geerlingguy.repo-remi + when: ansible_os_family == 'RedHat' + - role_under_test + - geerlingguy.php diff --git a/vars/Debian.yml b/vars/Debian.yml new file mode 100644 index 0000000..424c8c6 --- /dev/null +++ b/vars/Debian.yml @@ -0,0 +1,40 @@ +--- +# Configure PHP paths and packages for PHP 5.6 and PHP 7.0. +php_conf_paths: + - "/etc/php/{{ php_version }}/fpm" + - "/etc/php/{{ php_version }}/apache2" + - "/etc/php/{{ php_version }}/cli" +php_extension_conf_paths: + - "/etc/php/{{ php_version }}/fpm/conf.d" + - "/etc/php/{{ php_version }}/apache2/conf.d" + - "/etc/php/{{ php_version }}/cli/conf.d" +php_fpm_daemon: "php{{ php_version }}-fpm" +php_fpm_conf_path: "/etc/php/{{ php_version }}/fpm" +php_fpm_pool_conf_path: "{{ php_fpm_conf_path }}/pool.d/www.conf" +php_mysql_package: "php{{ php_version }}-mysql" +php_redis_package: "php{{ php_version }}-redis" +php_memcached_package: "php{{ php_version }}-memcached" +php_pgsql_package: "php{{ php_version }}-pgsql" + +php_tideways_module_path: "/usr/lib/php/{{ php_version }}/modules" +php_uploadprogress_module_path: "/usr/lib/php/{{ php_version }}/modules" +php_xdebug_module_path: "/usr/lib/php/{{ php_version }}/modules" +php_xhprof_module_path: "/usr/lib/php/{{ php_version }}/modules" + +php_packages: + - "php{{ php_version }}" + - "php{{ php_version }}-apcu" + - "php{{ php_version }}-cli" + - "php{{ php_version }}-common" + - "php{{ php_version }}-curl" + - "php{{ php_version }}-dev" + - "php{{ php_version }}-fpm" + - "php{{ php_version }}-gd" + - "php{{ php_version }}-imap" + - "php{{ php_version }}-json" + - "php{{ php_version }}-mbstring" + - "php{{ php_version }}-mcrypt" + - "php{{ php_version }}-opcache" + - "php{{ php_version }}-sqlite3" + - "php{{ php_version }}-xml" + - "php{{ php_version }}-yaml" diff --git a/vars/RedHat.yml b/vars/RedHat.yml new file mode 100644 index 0000000..bca09b4 --- /dev/null +++ b/vars/RedHat.yml @@ -0,0 +1,5 @@ +--- +php_tideways_module_path: "/usr/lib64/php{{ php_version }}/modules" +php_uploadprogress_module_path: "/usr/lib64/php{{ php_version }}/modules" +php_xdebug_module_path: "/usr/lib64/php{{ php_version }}/modules" +php_xhprof_module_path: "/usr/lib64/php{{ php_version }}/modules"