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-12-03 22:32:08 +07:00
nginx_htpasswd :
- name : 'hello'
description : 'Please login!'
users :
- name : 'hx'
password : 'asdfg'
state : 'absent'
- name : 'hanx'
password : 'qwerty'
- name : 'deleteme'
description : 'Please login!'
users : [ ]
state : 'absent'
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'
2015-10-15 21:21:36 +07:00
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 :
2015-09-21 16:47:49 +07:00
- 'autoindex off;'
2015-07-31 05:38:16 +07:00
location :
'/test' :
- 'return 403;'
'/gunther' :
- 'return 404;'
2015-12-03 22:32:08 +07:00
- name : 'test-htpasswd.local'
template : '_base'
location :
'/hello' :
- htpasswd : 'hello'
- 'default_type "text/html; charset=UTF-8";'
- 'echo hello;'
- name : 'test-htpasswd-all.local'
template : '_base'
htpasswd : 'hello'
2015-11-03 20:31:50 +07:00
- name : 'test-location.local'
template : '_base'
location :
'/' :
- 'alias /var/tmp;'
2015-10-22 15:25:30 +07:00
- name : 'test-php.local'
2015-09-21 16:47:49 +07:00
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'
2015-11-02 22:30:46 +07:00
- name : 'test-php-index.local'
template : '_php_index'
2015-10-22 15:25:30 +07:00
- name : 'test-proxy.local'
2015-10-09 19:31:01 +07:00
listen :
- 8080
2015-10-08 23:21:40 +07:00
template : '_proxy'
upstream_name : 'test'
2015-10-22 15:25:30 +07:00
- 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 --
2015-11-02 22:30:46 +07:00
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"
2015-12-03 23:09:29 +07:00
with_items : [ '{{ nginx_root }}/test.local/public' , '/var/tmp' , '{{ nginx_root }}/test-htpasswd-all.local/public' ]
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
2015-11-02 22:30:46 +07:00
- 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
2015-11-02 22:30:46 +07:00
register : r
failed_when : r.stdout.find('301 Moved Permanently') == -1
2015-12-03 22:32:08 +07:00
- name : -- VERIFY AUTH BASIC NONE --
command : "curl -H 'Host: test-htpasswd.local' http://127.0.0.1/hello"
changed_when : false
register : authnone
failed_when : authnone.stdout.find('401 Authorization Required') == -1
- name : -- VERIFY AUTH BASIC FAIL --
command : "curl -u fail:fail -H 'Host: test-htpasswd.local' http://127.0.0.1/hello"
changed_when : false
register : authfail
failed_when : authfail.stdout.find('401 Authorization Required') == -1
- name : -- VERIFY AUTH BASIC OK --
command : "curl -u hanx:qwerty -H 'Host: test-htpasswd.local' http://127.0.0.1/hello"
changed_when : false
register : authok
failed_when : authok.stdout.find('hello') == -1
2015-12-03 23:09:29 +07:00
- name : -- VERIFY AUTH BASIC FAIL GLOBAL --
command : "curl -u fail:fail -H 'Host: test-htpasswd-all.local' http://127.0.0.1/"
changed_when : false
register : authgfail
failed_when : authgfail.stdout.find('401 Authorization Required') == -1
- name : -- VERIFY AUTH BASIC OK --
command : "curl -u hanx:qwerty -H 'Host: test-htpasswd-all.local' http://127.0.0.1/"
changed_when : false
register : authgok
failed_when : authgok.stdout.find('401 Authorization Required') != -1