-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4502f41
commit 2b4d55d
Showing
18 changed files
with
347 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
> * installs apache2 | ||
> * configures apache2 | ||
> * enables/disables confs | ||
> * creates sites | ||
> * enables/disables sites | ||
> * enables/disables modules | ||
> * optionally removes default host | ||
|
@@ -36,24 +37,15 @@ $ git clone https://github.com/weareinteractive/ansible-apache2.git | |
|
||
## Dependencies | ||
|
||
* Apache 2.2 | 2.4 | ||
* Tested with Apache 2.2 | 2.4 | ||
* [franklinkim.openssl](https://github.com/weareinteractive/ansible-openssl) | ||
* [franklinkim.htpasswd](https://github.com/weareinteractive/ansible-htpasswd) | ||
|
||
## Variables | ||
|
||
Here is a list of all the default variables for this role, which are also available in `defaults/main.yml`. | ||
|
||
``` | ||
# apache2_module: | ||
# - { id: auth, state: absent } | ||
# - { id: rewrite, state: present } | ||
# apache2_confs: | ||
# - { id: security, state: absent } | ||
# - { id: mime, state: present } | ||
# apache2_sites: | ||
# - { id: default, state: absent } | ||
# - { id: foobar, state: present } | ||
# | ||
# ports to listen to | ||
apache2_ports: [80] | ||
# ssl ports to listen to | ||
|
@@ -80,6 +72,54 @@ apache2_server_signiture: 'Off' | |
apache2_trace_enable: 'Off' | ||
``` | ||
|
||
Module and confs might be defined through: | ||
|
||
``` | ||
# id of the conf or module | ||
id: auth | ||
# state: absent | present | ||
state: absent | ||
``` | ||
|
||
A site might be defined through: | ||
|
||
``` | ||
# site id (required) | ||
id: foo | ||
# server name (required) | ||
name: foo.com | ||
# ip to listen to | ||
ip: '*' | ||
# port to listen to | ||
port: 80 | ||
# state: present | absent | ||
state: present | ||
# create the /var/www/[id]/htdocs folder | ||
add_webroot: no | ||
# /etc/nginx/rules/[rule].conf to include | ||
rules: [] | ||
# list of server aliases | ||
aliases: [] | ||
# list of server redirects | ||
redirects: [] | ||
# enable ssl | ||
ssl: | ||
# redirect http to https | ||
only: no | ||
# port to listen to | ||
port: 443 | ||
# @see franklinkim.openssl | ||
key_name: mykey | ||
cert_name: mycert | ||
# enable auth | ||
auth: | ||
# @see franklinkim.htpasswd | ||
name: foo | ||
file: foo | ||
# custom string to append to the site | ||
append: false | ||
``` | ||
|
||
## Handlers | ||
|
||
These are the handlers that are defined in `handlers/main.yml`. | ||
|
@@ -117,6 +157,25 @@ These can be included into your site definitions. | |
- { id: mime, state: present } | ||
- { id: headers, state: present } | ||
- { id: rewrite, state: present } | ||
apache2_remove_default: yes | ||
htpasswd: | ||
- name: foobar | ||
users: | ||
- { name: foobar, password: foobar } | ||
openssl_self_signed: | ||
- { name: 'foobar.local', country: 'DE', state: 'Bavaria', city: 'Munich', organization: 'Foo Bar', email: '[email protected]' } | ||
apache2_sites_html: | ||
- id: foobar | ||
state: present | ||
name: foobar.local | ||
rules: ['mimes', 'expires', 'security', 'compression'] | ||
add_webroot: yes | ||
auth: | ||
name: Foo Bar | ||
file: foobar | ||
ssl: | ||
key_name: foobar.local | ||
cert_name: foobar.local | ||
``` | ||
|
||
## Testing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# {{ ansible_managed }} | ||
|
||
{% include "etc-apache2-sites-available-site/redirect.j2" %} | ||
|
||
{% if item.ssl is defined %} | ||
<VirtualHost {{ item.ip|default('*') }}:{{item.ssl.port|default(443)}}> | ||
|
||
{% include "etc-apache2-sites-available-site/body.j2" %} | ||
|
||
{% include "etc-apache2-sites-available-site/ssl.j2" %} | ||
|
||
</VirtualHost> | ||
{% endif %} | ||
|
||
<VirtualHost {{ item.ip|default('*') }}:{{item.port|default(80)}}> | ||
|
||
{% include "etc-apache2-sites-available-site/body.j2" %} | ||
|
||
</VirtualHost> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
ServerName {{ item.name }} | ||
DocumentRoot /var/www/{{ item.id }}/htdocs | ||
{% for value in item.aliases|default([]) %} | ||
ServerAlias {{ value }} | ||
{% endfor %} | ||
|
||
# --- rules ---------------------------------------------------------------- | ||
|
||
{% for val in item.rules|default([]) %} | ||
include rules/{{ val }}.conf | ||
{% endfor %} | ||
|
||
# --- directories ----------------------------------------------------------- | ||
|
||
<Directory /var/www/{{ item.id }}/htdocs> | ||
AllowOverride All | ||
Options FollowSymLinks | ||
Order allow,deny | ||
Allow from all | ||
</Directory> | ||
|
||
{% if item.auth is defined %} | ||
# --- auth ------------------------------------------------------------------ | ||
|
||
{% include "etc-apache2-sites-available-site/htpasswd.j2" %} | ||
{% endif %} | ||
|
||
# --- logging --------------------------------------------------------------- | ||
|
||
LogLevel warn | ||
ErrorLog /var/log/apache2/error-{{ item.id }}.log | ||
CustomLog /var/log/apache2/access-{{ item.id }}.log combined | ||
|
||
{% if item.append is defined %} | ||
|
||
# --- appended -------------------------------------------------------------- | ||
|
||
{{ item.append }} | ||
{% endif %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Directory /var/www/{{ item.id }}/htdocs> | ||
AuthType Basic | ||
AuthBasicProvider file | ||
AuthUserFile /etc/htpasswd/{{ item.auth.file }} | ||
AuthName "{{ item.auth.name|default(item.id) }}" | ||
Require valid-user | ||
</Directory> |
28 changes: 28 additions & 0 deletions
28
templates/2.2/etc-apache2-sites-available-site/redirect.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% for value in item.redirects|default([]) %} | ||
{% if item.ssl is defined %} | ||
<VirtualHost {{ item.ip|default('*') }}:{{item.ssl.port|default(443)}}> | ||
ServerName {{ value }} | ||
|
||
{% include "etc-apache2-sites-available-site/ssl.j2" %} | ||
|
||
# logging | ||
LogLevel warn | ||
ErrorLog /var/log/apache2/error-{{ item.id }}.log | ||
CustomLog /var/log/apache2/access-{{ item.id }}.log combined | ||
|
||
# redirect | ||
Redirect permanent / https://{{ item.name }}/ | ||
</VirtualHost> | ||
{% endif %} | ||
<VirtualHost {{ item.ip|default('*') }}:{{item.port|default(80)}}> | ||
ServerName {{ value }} | ||
|
||
# logging | ||
LogLevel warn | ||
ErrorLog /var/log/apache2/error-{{ item.id }}.log | ||
CustomLog /var/log/apache2/access-{{ item.id }}.log combined | ||
|
||
# redirect | ||
Redirect permanent / http://{{ item.name }}/ | ||
</VirtualHost> | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# --- ssl ------------------------------------------------------------------- | ||
|
||
include rules/ssl.conf | ||
SSLCertificateFile {{ openssl_certs_path }}/{{ item.ssl.cert_name|default('server') }}.crt | ||
SSLCertificateKeyFile {{ openssl_keys_path }}/{{ item.ssl.key_name|default('server') }}.key | ||
{% if item.ssl.chain_name is defined %} | ||
SSLCACertificateFile {{ openssl_certs_path }}/{{ item.ssl.chain_name }}.crt | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# {{ ansible_managed }} | ||
|
||
{% include "etc-apache2-sites-available-site/redirect.j2" %} | ||
|
||
{% if item.ssl is defined %} | ||
<VirtualHost {{ item.ip|default('*') }}:{{item.ssl.port|default(443)}}> | ||
|
||
{% include "etc-apache2-sites-available-site/body.j2" %} | ||
|
||
{% include "etc-apache2-sites-available-site/ssl.j2" %} | ||
|
||
</VirtualHost> | ||
{% endif %} | ||
|
||
<VirtualHost {{ item.ip|default('*') }}:{{item.port|default(80)}}> | ||
|
||
{% include "etc-apache2-sites-available-site/body.j2" %} | ||
|
||
</VirtualHost> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
ServerName {{ item.name }} | ||
DocumentRoot /var/www/{{ item.id }}/htdocs | ||
{% for value in item.aliases|default([]) %} | ||
ServerAlias {{ value }} | ||
{% endfor %} | ||
|
||
# --- rules ---------------------------------------------------------------- | ||
|
||
{% for val in item.rules|default([]) %} | ||
include rules/{{ val }}.conf | ||
{% endfor %} | ||
|
||
# --- directories ----------------------------------------------------------- | ||
|
||
<Directory /var/www/{{ item.id }}/htdocs> | ||
AllowOverride All | ||
Options FollowSymLinks | ||
Require all granted | ||
Satisfy Any | ||
</Directory> | ||
|
||
{% if item.auth is defined %} | ||
# --- auth ------------------------------------------------------------------ | ||
|
||
{% include "etc-apache2-sites-available-site/htpasswd.j2" %} | ||
{% endif %} | ||
|
||
# --- logging --------------------------------------------------------------- | ||
|
||
LogLevel warn | ||
ErrorLog /var/log/apache2/error-{{ item.id }}.log | ||
CustomLog /var/log/apache2/access-{{ item.id }}.log combined | ||
|
||
{% if item.append is defined %} | ||
|
||
# --- appended -------------------------------------------------------------- | ||
|
||
{{ item.append }} | ||
{% endif %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Directory /var/www/{{ item.id }}/htdocs> | ||
AuthType Basic | ||
AuthBasicProvider file | ||
AuthUserFile /etc/htpasswd/{{ item.auth.file }} | ||
AuthName "{{ item.auth.name|default(item.id) }}" | ||
Require valid-user | ||
</Directory> |
Oops, something went wrong.