ansible-php/tests/test.yml

79 lines
2.3 KiB
YAML
Raw Normal View History

2015-07-23 21:35:25 +07:00
---
- hosts: all
2015-07-23 22:10:15 +07:00
vars:
vhost: 'test.local'
2015-07-24 15:03:11 +07:00
php_extra_packages:
2016-01-22 21:57:29 +07:00
- '{{ php_apt_prefix }}recode'
2015-07-27 23:09:52 +07:00
php_install_xdebug: true
2017-03-17 00:22:32 +07:00
2015-07-23 22:10:15 +07:00
pre_tasks:
2017-03-17 00:22:32 +07:00
- name: APT | Install packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600
with_items: ['apt-transport-https', 'curl', 'lsb-release', 'ca-certificates']
2017-06-06 21:27:11 +07:00
- name: INCLUDE | Dotdeb
include: includes/dotdeb.yml
2016-03-04 13:58:22 +07:00
when: >
ansible_distribution_major_version | version_compare(8, 'eq') and
2017-03-17 00:22:32 +07:00
php_version | version_compare('7.0', 'eq')
2017-06-06 21:27:11 +07:00
- name: INCLUDE | Sury
include: includes/sury.yml
when: >
2017-06-06 21:27:11 +07:00
ansible_distribution_major_version | version_compare(9, 'le') and
2017-03-17 00:22:32 +07:00
php_version | version_compare('7.1', 'eq')
2015-07-23 22:10:15 +07:00
- name: APT | Install nginx
apt: pkg=nginx state=present update_cache=yes cache_valid_time=3600
2017-03-17 00:22:32 +07:00
2015-07-24 14:48:47 +07:00
- name: SHELL | Get nginx version
shell: nginx -V 2>&1 | awk -F '/' '/nginx version/ { print $2 }'
register: nginx_version
changed_when: false
2017-03-17 00:22:32 +07:00
2015-07-24 14:48:47 +07:00
- set_fact: nginx_include="fastcgi_params"
2015-07-27 23:09:52 +07:00
when: nginx_version.stdout | version_compare('1.6', '<', true)
2017-03-17 00:22:32 +07:00
2015-07-24 14:48:47 +07:00
- set_fact: nginx_include="fastcgi.conf"
2015-07-27 23:09:52 +07:00
when: nginx_version.stdout | version_compare('1.6', '>=', true)
2017-03-17 00:22:32 +07:00
2016-01-22 21:57:29 +07:00
tasks:
2017-03-17 00:22:32 +07:00
2015-07-23 22:10:15 +07:00
- name: COPY | Vhost
copy: >
dest=/etc/nginx/sites-enabled/{{ vhost }}
2016-01-22 21:57:29 +07:00
content='server { server_name {{ vhost }}; root /var/www; location ~ \.php$ { include {{ nginx_include }}; fastcgi_pass unix:{{ php_default_fpm_sock }}; } }'
2015-07-23 22:10:15 +07:00
notify: reload nginx
2017-03-17 00:22:32 +07:00
2015-07-23 22:10:15 +07:00
handlers:
2017-03-17 00:22:32 +07:00
2015-07-23 22:10:15 +07:00
- name: reload nginx
service: name=nginx state=reloaded
2017-03-17 00:22:32 +07:00
2015-07-23 21:35:25 +07:00
roles:
- ../../
2017-03-17 00:22:32 +07:00
2015-07-23 22:10:15 +07:00
post_tasks:
2017-03-17 00:22:32 +07:00
2015-07-24 14:48:47 +07:00
- name: SHELL | Test php-cli
shell: php -i | grep '^PHP Version => {{ php_version }}' | head -n 1
2015-07-23 22:10:15 +07:00
changed_when: false
2016-01-22 21:57:29 +07:00
register: p
failed_when: p.stdout == ''
2017-03-17 00:22:32 +07:00
2015-07-23 22:10:15 +07:00
- name: FILE | Create /var/www
2015-07-23 23:10:17 +07:00
file: dest=/var/www state=directory
2017-03-17 00:22:32 +07:00
2015-07-23 22:10:15 +07:00
- name: COPY | Add phpinfo
copy: dest=/var/www/phpinfo.php content='<?php phpinfo();'
2017-03-17 00:22:32 +07:00
2015-07-24 14:48:47 +07:00
- name: SHELL | Check vhost
2017-06-06 21:27:11 +07:00
shell: "curl -v -H 'Host: {{ vhost }}' http://127.0.0.1/phpinfo.php 2> /dev/null | grep h1 | grep -o 'PHP Version {{ php_version }}' | sed -r 's/<//g'"
2017-03-17 00:31:16 +07:00
args:
warn: false
2015-07-23 22:10:15 +07:00
changed_when: false
2016-01-22 21:57:29 +07:00
register: c
failed_when: c.stdout == ''