2015-07-23 21:35:25 +07:00
|
|
|
---
|
|
|
|
|
|
|
|
- hosts: all
|
2022-10-06 19:47:06 +07:00
|
|
|
name: Test all
|
2015-07-23 22:10:15 +07:00
|
|
|
vars:
|
|
|
|
vhost: 'test.local'
|
2015-07-24 15:03:11 +07:00
|
|
|
php_extra_packages:
|
2019-12-26 20:13:00 +07:00
|
|
|
- '{{ php_package_prefix }}pgsql'
|
2015-07-27 23:09:52 +07:00
|
|
|
php_install_xdebug: true
|
2019-12-26 22:42:16 +07:00
|
|
|
php_autoremove_default_pool: true
|
2017-11-10 18:19:39 +07:00
|
|
|
php_ini_fpm:
|
|
|
|
display_errors: 'Off'
|
|
|
|
php_ini_cli:
|
|
|
|
error_reporting: 'E_ALL'
|
2017-11-22 23:02:51 +07:00
|
|
|
php_fpm_poold:
|
2019-04-19 19:36:35 +07:00
|
|
|
- pool_name: 'test_ansible'
|
2019-12-26 20:13:00 +07:00
|
|
|
listen: '/run/php/php-ansible1.sock'
|
2017-11-22 23:02:51 +07:00
|
|
|
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'
|
2019-12-26 20:13:00 +07:00
|
|
|
- name: 'test_ansible2'
|
|
|
|
user: 'foo'
|
2022-10-06 21:36:02 +07:00
|
|
|
php_env:
|
|
|
|
foo: bar
|
2019-12-26 20:13:00 +07:00
|
|
|
php_value:
|
2019-12-16 23:28:39 +07:00
|
|
|
display_errors: 'Off'
|
2019-12-26 20:13:00 +07:00
|
|
|
php_admin_value:
|
|
|
|
memory_limit: '98M'
|
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
|
|
|
|
2019-04-19 15:28:00 +07:00
|
|
|
- name: INCLUDE_TASKS | Pre tasks related to OS
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.include_tasks: "includes/pre_{{ ansible_os_family }}.yml"
|
2017-03-17 00:22:32 +07:00
|
|
|
|
2019-12-26 20:13:00 +07:00
|
|
|
- name: USER | Create PHP user
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.user:
|
2019-12-26 20:13:00 +07:00
|
|
|
name: 'foo'
|
2021-09-01 14:57:23 +07:00
|
|
|
system: true
|
|
|
|
create_home: false
|
2019-12-26 20:13:00 +07:00
|
|
|
shell: '/usr/sbin/nologin'
|
|
|
|
|
2016-01-22 21:57:29 +07:00
|
|
|
tasks:
|
2017-03-17 00:22:32 +07:00
|
|
|
|
2017-11-22 23:02:51 +07:00
|
|
|
- name: TEMPLATE | Nginx site config
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.template:
|
2018-03-19 03:29:47 +07:00
|
|
|
src: "templates/nginx.conf.j2"
|
2022-10-06 19:47:06 +07:00
|
|
|
dest: "{{ __nginx_conf }}"
|
2021-09-01 14:57:23 +07:00
|
|
|
mode: 0644
|
|
|
|
owner: root
|
|
|
|
group: root
|
2022-10-06 19:47:06 +07:00
|
|
|
notify: Reload nginx
|
2017-11-22 23:02:51 +07:00
|
|
|
|
2018-03-19 03:29:47 +07:00
|
|
|
- name: COMMAND | Fix nginx config
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.command: "cp {{ __nginx_conf | dirname }}/fastcgi_params {{ __nginx_conf | dirname }}/fastcgi.conf"
|
2018-03-19 03:29:47 +07:00
|
|
|
args:
|
|
|
|
creates: "{{ __nginx_conf | dirname }}/fastcgi.conf"
|
2022-10-06 19:47:06 +07:00
|
|
|
notify: Reload nginx
|
2018-03-19 03:29:47 +07:00
|
|
|
|
|
|
|
- name: LINEINFILE | Fix nginx config (second step)
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.lineinfile:
|
2018-03-19 03:29:47 +07:00
|
|
|
regexp: '^fastcgi_param\s+SCRIPT_FILENAME'
|
|
|
|
line: "fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;"
|
|
|
|
dest: "{{ __nginx_conf | dirname }}/fastcgi.conf"
|
2022-10-06 19:47:06 +07:00
|
|
|
notify: Reload nginx
|
2017-03-17 00:22:32 +07:00
|
|
|
|
2019-01-28 20:46:58 +07:00
|
|
|
- name: SERVICE | Ensure nginx is started
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.service:
|
2019-01-28 20:46:58 +07:00
|
|
|
name: nginx
|
|
|
|
state: started
|
|
|
|
when: ansible_virtualization_type != 'docker'
|
|
|
|
|
2022-10-06 19:47:06 +07:00
|
|
|
- name: Start nginx if testing with Docker
|
|
|
|
when: ansible_virtualization_type == 'docker'
|
|
|
|
block:
|
2019-01-28 20:46:58 +07:00
|
|
|
|
2021-09-01 14:57:23 +07:00
|
|
|
- name: COMMAND | Docker nginx status
|
|
|
|
ansible.builtin.command: service nginx status
|
|
|
|
args:
|
|
|
|
warn: false
|
|
|
|
changed_when: false
|
|
|
|
failed_when: false
|
|
|
|
register: ngs
|
2019-01-28 20:46:58 +07:00
|
|
|
|
2021-09-01 14:57:23 +07:00
|
|
|
- name: COMMAND | Docker start nginx
|
|
|
|
ansible.builtin.command: service nginx start
|
|
|
|
args:
|
|
|
|
warn: false
|
|
|
|
when: ngs.stdout.find('nginx is not running') != -1
|
2019-01-28 20:46:58 +07:00
|
|
|
|
2015-07-23 22:10:15 +07:00
|
|
|
handlers:
|
2017-03-17 00:22:32 +07:00
|
|
|
|
2022-10-06 19:47:06 +07:00
|
|
|
- name: Reload nginx
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.service:
|
2018-03-18 23:28:57 +07:00
|
|
|
name: nginx
|
|
|
|
state: reloaded
|
2022-10-06 19:47:06 +07:00
|
|
|
notify: Docker reload nginx
|
2019-01-28 20:46:58 +07:00
|
|
|
|
2022-10-06 19:47:06 +07:00
|
|
|
- name: Docker reload nginx
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.command: service nginx reload
|
2019-01-28 20:46:58 +07:00
|
|
|
args:
|
|
|
|
warn: false
|
2022-10-06 19:47:06 +07:00
|
|
|
notify: Docker reload nginx
|
2019-01-28 20:46:58 +07:00
|
|
|
when: ansible_virtualization_type == 'docker'
|
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
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.shell: set -o pipefail && 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 == ''
|
2021-09-01 14:57:23 +07:00
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
2017-03-17 00:22:32 +07:00
|
|
|
|
2015-07-23 22:10:15 +07:00
|
|
|
- name: FILE | Create /var/www
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.file:
|
2018-03-18 23:28:57 +07:00
|
|
|
dest: /var/www
|
|
|
|
state: directory
|
2021-09-01 14:57:23 +07:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
2017-03-17 00:22:32 +07:00
|
|
|
|
2015-07-23 22:10:15 +07:00
|
|
|
- name: COPY | Add phpinfo
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.copy:
|
2018-03-18 23:28:57 +07:00
|
|
|
dest: /var/www/phpinfo.php
|
|
|
|
content: '<?php phpinfo();'
|
2021-09-01 14:57:23 +07:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0644
|
2017-03-17 00:22:32 +07:00
|
|
|
|
2019-12-26 20:13:00 +07:00
|
|
|
- name: COPY | Add ini test file
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.copy:
|
2019-12-26 20:13:00 +07:00
|
|
|
dest: /var/www/ini.php
|
|
|
|
content: '<?php echo ini_get("memory_limit") . "\n";'
|
2021-09-01 14:57:23 +07:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0644
|
2019-12-26 20:13:00 +07:00
|
|
|
|
2015-07-24 14:48:47 +07:00
|
|
|
- name: SHELL | Check vhost
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.shell: "set -o pipefail && 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
|
2021-09-01 14:57:23 +07:00
|
|
|
executable: /bin/bash
|
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 == ''
|
2017-11-22 23:02:51 +07:00
|
|
|
|
2019-12-26 20:13:00 +07:00
|
|
|
- name: SHELL | Check custom php value
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.shell: "curl -H 'Host: {{ vhost }}' http://127.0.0.1/ini.php 2> /dev/null"
|
2019-12-26 20:13:00 +07:00
|
|
|
args:
|
|
|
|
warn: false
|
|
|
|
changed_when: false
|
|
|
|
register: c
|
|
|
|
failed_when: 'php_fpm_poold.1.php_admin_value.memory_limit not in c.stdout'
|
|
|
|
|
2017-11-22 23:02:51 +07:00
|
|
|
- name: URI | Check ping
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.uri:
|
2017-11-22 23:02:51 +07:00
|
|
|
url: "http://localhost{{ php_fpm_poold.0.ping_path }}"
|
|
|
|
when: php_fpm_poold.0.ping_path is defined
|
|
|
|
|
|
|
|
- name: URI | Check status
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.uri:
|
2017-11-22 23:02:51 +07:00
|
|
|
url: "http://localhost{{ php_fpm_poold.0.status_path }}"
|
|
|
|
when: php_fpm_poold.0.status_path is defined
|
2022-02-22 19:41:02 +07:00
|
|
|
|
2022-10-06 19:47:06 +07:00
|
|
|
- name: Debian extra checks
|
|
|
|
when: ansible_os_family == 'Debian'
|
|
|
|
block:
|
2022-02-22 19:41:02 +07:00
|
|
|
|
|
|
|
- name: SHELL | Check if we installed multiple PHP versions
|
|
|
|
ansible.builtin.shell: set -o pipefail && (dpkg -l | grep 'php[[:digit:]].*common' | wc -l)
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
|
|
|
failed_when: false
|
|
|
|
changed_when: false
|
|
|
|
register: check_multiple_php
|
|
|
|
|
|
|
|
|
|
|
|
- name: FAIL | If we have multiple PHP version
|
|
|
|
ansible.builtin.fail:
|
|
|
|
msg: "Multiple PHP versions detected"
|
|
|
|
when: check_multiple_php.stdout != '1'
|