ansible-php/tests/test.yml

142 lines
3.7 KiB
YAML

---
- hosts: all
vars:
vhost: 'test.local'
php_extra_packages:
- '{{ php_package_prefix }}recode'
php_install_xdebug: true
php_ini_fpm:
display_errors: 'Off'
php_ini_cli:
error_reporting: 'E_ALL'
php_fpm_poold:
- pool_name: 'test_ansible'
listen: '{{ php_default_fpm_sock }}'
pm: 'dynamic'
pm_max_children: 250
pm_start_servers: 10
pm_min_spare_servers: 10
pm_max_spare_servers: 20
status_path: '/status'
ping_path: '/ping'
ping_response: 'ok'
php_flag:
display_errors: 'Off'
php_admin_flag:
memory_limit: '128M'
- pool_name: 'test_ansible2'
pm: 'dynamic'
pm_max_children: 250
pm_start_servers: 10
pm_min_spare_servers: 10
pm_max_spare_servers: 20
php_flag:
display_errors: 'On'
php_admin_flag:
memory_limit: '64M'
pre_tasks:
- name: INCLUDE_TASKS | Pre tasks related to OS
include_tasks: "includes/pre_{{ ansible_os_family }}.yml"
tasks:
- name: TEMPLATE | Nginx site config
template:
src: "templates/nginx.conf.j2"
dest: "{{ __nginx_conf }}"
notify: reload nginx
- name: COMMAND | Fix nginx config
command: "cp {{ __nginx_conf | dirname }}/fastcgi_params {{ __nginx_conf | dirname }}/fastcgi.conf"
args:
creates: "{{ __nginx_conf | dirname }}/fastcgi.conf"
notify: reload nginx
- name: LINEINFILE | Fix nginx config (second step)
lineinfile:
regexp: '^fastcgi_param\s+SCRIPT_FILENAME'
line: "fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;"
dest: "{{ __nginx_conf | dirname }}/fastcgi.conf"
notify: reload nginx
- name: SERVICE | Ensure nginx is started
service:
name: nginx
state: started
when: ansible_virtualization_type != 'docker'
- block:
- name: COMMAND | Docker nginx status
command: service nginx status
args:
warn: false
changed_when: false
failed_when: false
register: ngs
- name: COMMAND | Docker start nginx
command: service nginx start
args:
warn: false
when: ngs.stdout.find('nginx is not running') != -1
when: ansible_virtualization_type == 'docker'
handlers:
- name: reload nginx
service:
name: nginx
state: reloaded
notify: docker reload nginx
- name: docker reload nginx
command: service nginx reload
args:
warn: false
notify: docker reload nginx
when: ansible_virtualization_type == 'docker'
roles:
- ../../
post_tasks:
- name: SHELL | Test php-cli
shell: php -i | grep '^PHP Version => {{ php_version }}' | head -n 1
changed_when: false
register: p
failed_when: p.stdout == ''
- name: FILE | Create /var/www
file:
dest: /var/www
state: directory
- name: COPY | Add phpinfo
copy:
dest: /var/www/phpinfo.php
content: '<?php phpinfo();'
- name: SHELL | Check vhost
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'"
args:
warn: false
changed_when: false
register: c
failed_when: c.stdout == ''
- name: URI | Check ping
uri:
url: "http://localhost{{ php_fpm_poold.0.ping_path }}"
when: php_fpm_poold.0.ping_path is defined
- name: URI | Check status
uri:
url: "http://localhost{{ php_fpm_poold.0.status_path }}"
when: php_fpm_poold.0.status_path is defined