mirror of
https://github.com/geerlingguy/ansible-role-php-versions.git
synced 2024-11-28 11:15:20 +01:00
Switch tests to use Molecule.
This commit is contained in:
parent
dd4fbe9a46
commit
7c0b3771d9
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
*.retry
|
*.retry
|
||||||
tests/test.sh
|
*/__pycache__
|
||||||
|
*.pyc
|
||||||
|
74
.travis.yml
74
.travis.yml
@ -1,53 +1,49 @@
|
|||||||
---
|
---
|
||||||
|
language: python
|
||||||
services: docker
|
services: docker
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
php_version: "7.1"
|
- ROLE_NAME: php-versions
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
# Default - PHP 7.1
|
# Default PHP version.
|
||||||
- distro: centos7
|
- MOLECULE_DISTRO: centos7
|
||||||
- distro: debian9
|
MOLECULE_DOCKER_COMMAND: /usr/lib/systemd/systemd
|
||||||
- distro: ubuntu1804
|
- MOLECULE_DISTRO: ubuntu1804
|
||||||
- distro: ubuntu1604
|
- MOLECULE_DISTRO: ubuntu1604
|
||||||
|
- MOLECULE_DISTRO: debian9
|
||||||
|
|
||||||
# PHP 7.2
|
# PHP 7.2.
|
||||||
- distro: centos7
|
- MOLECULE_DISTRO: centos7
|
||||||
playbook: test-7.2.yml
|
MOLECULE_DOCKER_COMMAND: /usr/lib/systemd/systemd
|
||||||
php_version: "7.2"
|
MOLECULE_PLAYBOOK: playbook-7.2.yml
|
||||||
- distro: ubuntu1804
|
- MOLECULE_DISTRO: ubuntu1804
|
||||||
playbook: test-7.2.yml
|
MOLECULE_PLAYBOOK: playbook-7.2.yml
|
||||||
php_version: "7.2"
|
- MOLECULE_DISTRO: ubuntu1604
|
||||||
- distro: ubuntu1604
|
MOLECULE_PLAYBOOK: playbook-7.2.yml
|
||||||
playbook: test-7.2.yml
|
- MOLECULE_DISTRO: debian9
|
||||||
php_version: "7.2"
|
MOLECULE_PLAYBOOK: playbook-7.2.yml
|
||||||
- distro: debian9
|
|
||||||
playbook: test-7.2.yml
|
|
||||||
php_version: "7.2"
|
|
||||||
|
|
||||||
# PHP 5.6
|
# PHP 5.6.
|
||||||
- distro: centos7
|
- MOLECULE_DISTRO: centos7
|
||||||
playbook: test-5.6.yml
|
MOLECULE_DOCKER_COMMAND: /usr/lib/systemd/systemd
|
||||||
php_version: "5.6"
|
MOLECULE_PLAYBOOK: playbook-5.6.yml
|
||||||
- distro: ubuntu1804
|
- MOLECULE_DISTRO: ubuntu1804
|
||||||
playbook: test-5.6.yml
|
MOLECULE_PLAYBOOK: playbook-5.6.yml
|
||||||
php_version: "5.6"
|
|
||||||
|
install:
|
||||||
|
# Install test dependencies.
|
||||||
|
- pip install molecule docker
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
# Use actual Ansible Galaxy role name for the project directory.
|
||||||
|
- cd ../
|
||||||
|
- mv ansible-role-$ROLE_NAME geerlingguy.$ROLE_NAME
|
||||||
|
- cd geerlingguy.$ROLE_NAME
|
||||||
|
|
||||||
script:
|
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.
|
# Run tests.
|
||||||
- ${PWD}/tests/test.sh
|
- molecule test
|
||||||
|
|
||||||
# Run script to test PHP version.
|
|
||||||
- 'docker exec ${container_id} env TERM=xterm php -v | grep -F "${php_version}."'
|
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
||||||
|
@ -16,7 +16,7 @@ Available variables are listed below, along with default values (see `defaults/m
|
|||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
php_versions_install_recommends: no
|
php_versions_install_recommends: false
|
||||||
|
|
||||||
(For Debian OSes only) Whether to install recommended packages. This is set to `no` by default because setting it to `yes` often leads to multiple PHP versions being installed (thus making a bit of a mess) when using repos like Ondrej's PHP PPA for Ubuntu.
|
(For Debian OSes only) Whether to install recommended packages. This is set to `no` by default because setting it to `yes` often leads to multiple PHP versions being installed (thus making a bit of a mess) when using repos like Ondrej's PHP PPA for Ubuntu.
|
||||||
|
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
php_version: '7.1'
|
php_version: '7.1'
|
||||||
|
|
||||||
# For Debian OSes only.
|
# For Debian OSes only.
|
||||||
php_versions_install_recommends: no
|
php_versions_install_recommends: false
|
||||||
|
27
molecule/default/molecule.yml
Normal file
27
molecule/default/molecule.yml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
lint:
|
||||||
|
name: yamllint
|
||||||
|
options:
|
||||||
|
config-file: molecule/default/yaml-lint.yml
|
||||||
|
platforms:
|
||||||
|
- name: instance
|
||||||
|
image: geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible
|
||||||
|
command: ${MOLECULE_DOCKER_COMMAND:-"sleep infinity"}
|
||||||
|
privileged: true
|
||||||
|
pre_build_image: true
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
lint:
|
||||||
|
name: ansible-lint
|
||||||
|
playbooks:
|
||||||
|
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
|
||||||
|
scenario:
|
||||||
|
name: default
|
||||||
|
verifier:
|
||||||
|
name: testinfra
|
||||||
|
lint:
|
||||||
|
name: flake8
|
24
molecule/default/playbook-5.6.yml
Normal file
24
molecule/default/playbook-5.6.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
|
||||||
|
vars:
|
||||||
|
php_enable_webserver: false
|
||||||
|
php_version: '5.6'
|
||||||
|
|
||||||
|
pre_tasks:
|
||||||
|
- name: Update apt cache.
|
||||||
|
apt: update_cache=true cache_valid_time=600
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: geerlingguy.repo-remi
|
||||||
|
when: ansible_os_family == 'RedHat'
|
||||||
|
- role: geerlingguy.php-versions
|
||||||
|
- role: geerlingguy.php
|
||||||
|
|
||||||
|
post_tasks:
|
||||||
|
- name: Confirm PHP version is correct.
|
||||||
|
shell: "php -v | grep -F '{{ php_version }}'"
|
||||||
|
changed_when: false
|
24
molecule/default/playbook-7.2.yml
Normal file
24
molecule/default/playbook-7.2.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
|
||||||
|
vars:
|
||||||
|
php_enable_webserver: false
|
||||||
|
php_version: '7.2'
|
||||||
|
|
||||||
|
pre_tasks:
|
||||||
|
- name: Update apt cache.
|
||||||
|
apt: update_cache=true cache_valid_time=600
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: geerlingguy.repo-remi
|
||||||
|
when: ansible_os_family == 'RedHat'
|
||||||
|
- role: geerlingguy.php-versions
|
||||||
|
- role: geerlingguy.php
|
||||||
|
|
||||||
|
post_tasks:
|
||||||
|
- name: Confirm PHP version is correct.
|
||||||
|
shell: "php -v | grep -F '{{ php_version }}'"
|
||||||
|
changed_when: false
|
24
molecule/default/playbook.yml
Normal file
24
molecule/default/playbook.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
|
||||||
|
vars:
|
||||||
|
php_enable_webserver: false
|
||||||
|
php_version: '7.1'
|
||||||
|
|
||||||
|
pre_tasks:
|
||||||
|
- name: Update apt cache.
|
||||||
|
apt: update_cache=true cache_valid_time=600
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: geerlingguy.repo-remi
|
||||||
|
when: ansible_os_family == 'RedHat'
|
||||||
|
- role: geerlingguy.php-versions
|
||||||
|
- role: geerlingguy.php
|
||||||
|
|
||||||
|
post_tasks:
|
||||||
|
- name: Confirm PHP version is correct.
|
||||||
|
shell: "php -v | grep -F '{{ php_version }}'"
|
||||||
|
changed_when: false
|
14
molecule/default/tests/test_default.py
Normal file
14
molecule/default/tests/test_default.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import testinfra.utils.ansible_runner
|
||||||
|
|
||||||
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||||
|
|
||||||
|
|
||||||
|
def test_hosts_file(host):
|
||||||
|
f = host.file('/etc/hosts')
|
||||||
|
|
||||||
|
assert f.exists
|
||||||
|
assert f.user == 'root'
|
||||||
|
assert f.group == 'root'
|
6
molecule/default/yaml-lint.yml
Normal file
6
molecule/default/yaml-lint.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
extends: default
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 120
|
||||||
|
level: warning
|
@ -17,10 +17,10 @@
|
|||||||
# Debian-specific tasks.
|
# Debian-specific tasks.
|
||||||
- name: Add dependencies for PHP versions (Debian).
|
- name: Add dependencies for PHP versions (Debian).
|
||||||
apt:
|
apt:
|
||||||
name: "{{ item }}"
|
name:
|
||||||
with_items:
|
|
||||||
- apt-transport-https
|
- apt-transport-https
|
||||||
- ca-certificates
|
- ca-certificates
|
||||||
|
state: present
|
||||||
when: ansible_distribution == "Debian"
|
when: ansible_distribution == "Debian"
|
||||||
|
|
||||||
- name: Add Ondrej Sury's apt key (Debian).
|
- name: Add Ondrej Sury's apt key (Debian).
|
||||||
@ -37,19 +37,18 @@
|
|||||||
when: ansible_distribution == "Debian"
|
when: ansible_distribution == "Debian"
|
||||||
|
|
||||||
- name: Update apt caches after repo is added (Debian).
|
- name: Update apt caches after repo is added (Debian).
|
||||||
apt: update_cache=yes
|
apt: update_cache=true
|
||||||
when: php_ondrej_debian_repo.changed and (ansible_distribution == "Debian")
|
when: php_ondrej_debian_repo.changed and (ansible_distribution == "Debian")
|
||||||
|
|
||||||
# PHP package purges.
|
# PHP package purges.
|
||||||
- name: Purge PHP version packages.
|
- name: Purge PHP version packages.
|
||||||
apt:
|
apt:
|
||||||
name: "{{ item }}"
|
name:
|
||||||
state: absent
|
|
||||||
purge: yes
|
|
||||||
force: yes
|
|
||||||
when: "'php' + php_version not in item"
|
|
||||||
with_items:
|
|
||||||
- php5.6-common
|
- php5.6-common
|
||||||
- php7.0-common
|
- php7.0-common
|
||||||
- php7.1-common
|
- php7.1-common
|
||||||
- php7.2-common
|
- php7.2-common
|
||||||
|
state: absent
|
||||||
|
purge: true
|
||||||
|
force: true
|
||||||
|
when: "'php' + php_version not in item"
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
# 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)`
|
|
@ -1,17 +0,0 @@
|
|||||||
---
|
|
||||||
- hosts: all
|
|
||||||
|
|
||||||
vars:
|
|
||||||
php_enable_webserver: false
|
|
||||||
php_version: "5.6"
|
|
||||||
|
|
||||||
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
|
|
@ -1,17 +0,0 @@
|
|||||||
---
|
|
||||||
- hosts: all
|
|
||||||
|
|
||||||
vars:
|
|
||||||
php_enable_webserver: false
|
|
||||||
php_version: "7.2"
|
|
||||||
|
|
||||||
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
|
|
@ -1,16 +0,0 @@
|
|||||||
---
|
|
||||||
- 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
|
|
@ -1,3 +1,4 @@
|
|||||||
|
---
|
||||||
__php_packages:
|
__php_packages:
|
||||||
- "php{{ php_version }}"
|
- "php{{ php_version }}"
|
||||||
- "php{{ php_version }}-apcu"
|
- "php{{ php_version }}-apcu"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
# Configure PHP paths and packages for PHP 5.6 and PHP 7.0.
|
# Configure PHP paths and packages.
|
||||||
__php_conf_paths:
|
__php_conf_paths:
|
||||||
- "/etc/php/{{ php_version }}/fpm"
|
- "/etc/php/{{ php_version }}/fpm"
|
||||||
- "/etc/php/{{ php_version }}/apache2"
|
- "/etc/php/{{ php_version }}/apache2"
|
||||||
|
Loading…
Reference in New Issue
Block a user