ansible-nginx/tests/test.yml

81 lines
2.6 KiB
YAML
Raw Normal View History

2015-07-15 17:14:39 +07:00
---
- hosts: all
2015-07-15 21:26:27 +07:00
pre_tasks:
2015-07-15 22:24:50 +07:00
- apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
with_items:
- php5-fpm
2015-08-04 18:27:52 +07:00
- curl
2015-07-15 20:18:51 +07:00
vars:
2015-07-15 21:26:27 +07:00
nginx_php: true
2015-10-08 23:21:40 +07:00
nginx_upstreams:
- name: 'test'
servers:
2015-10-09 22:54:07 +07:00
- path: '127.0.0.1:80'
2015-10-08 23:21:40 +07:00
max_conns: 150
weight: 10
down: false
2015-07-15 20:18:51 +07:00
nginx_vhosts:
2015-07-30 18:02:21 +07:00
- name:
- 'test.local'
- 'test-alias.local'
- 'test2-alias.local'
template: '_base'
override_try_files: '$uri $uri index.htm index.html'
2015-10-19 14:39:51 +07:00
manage_local_content: false
2015-09-09 22:44:53 +07:00
more:
- 'autoindex off;'
2015-07-31 05:38:16 +07:00
location:
'/test':
- 'return 403;'
'/gunther':
- 'return 404;'
2015-11-03 20:31:50 +07:00
- name: 'test-location.local'
template: '_base'
location:
'/':
- 'alias /var/tmp;'
- name: 'test-php.local'
upstream_params:
- 'fastcgi_param FOO bar;'
2015-07-30 20:53:45 +07:00
redirect_from:
- 'www.test-php.local'
2015-07-30 18:02:21 +07:00
template: '_php'
- name: 'test-php-index.local'
template: '_php_index'
- name: 'test-proxy.local'
listen:
- 8080
2015-10-08 23:21:40 +07:00
template: '_proxy'
upstream_name: 'test'
- name: 'deleted.local'
2015-07-31 06:02:37 +07:00
delete: true
2015-12-01 21:46:57 +07:00
- name: 'redirect-to.local'
redirect_to: 'http://test.local'
2015-07-15 17:14:39 +07:00
roles:
- ../../
2015-07-15 22:24:50 +07:00
post_tasks:
2015-07-16 21:24:44 +07:00
- name: -- Add PHP file --
copy: dest="{{ nginx_root }}/{{ item }}/public/index.php" content="<?php phpinfo();"
with_items: ['test-php.local', 'test-php-index.local']
2015-07-16 21:24:44 +07:00
- name: -- Add HTML file --
2015-11-03 20:31:50 +07:00
copy: dest="{{ item }}/index.html" content="Index HTML test OK\n"
with_items: ['{{ nginx_root }}/test.local/public', '/var/tmp']
2015-07-15 22:24:50 +07:00
- name: -- VERIFY VHOSTS --
2015-11-02 23:44:09 +07:00
command: "curl -H 'Host: {{ item.name if item.name is string else item.name[0] }}' http://127.0.0.1{% if item.listen is defined %}:{{ item.listen[0] }}{% endif %}/"
2015-07-15 22:24:50 +07:00
with_items: nginx_vhosts
2015-08-04 17:40:04 +07:00
when: item.delete is undefined or not item.delete
2015-07-15 22:24:50 +07:00
changed_when: false
- name: -- VERIFY FORBIDDEN --
command: "curl -H 'Host: test-php-index.local' http://127.0.0.1/phpinfo.php"
register: f
failed_when: f.stdout.find('403 Forbidden') == -1
changed_when: false
2015-08-04 17:26:38 +07:00
- name: -- VERIFY REDIRECT VHOSTS --
2015-11-02 23:44:09 +07:00
command: "curl -H 'Host: {{ item.redirect_from[0] }}' http://127.0.0.1/"
2015-08-04 17:26:38 +07:00
with_items: nginx_vhosts
2015-08-04 17:40:04 +07:00
when: item.redirect_from is defined and (item.delete is undefined or not item.delete)
2015-08-04 17:26:38 +07:00
changed_when: false
register: r
failed_when: r.stdout.find('301 Moved Permanently') == -1