Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 3 new features (Apache MPM configuration, and Directory Listing and Index Management, Extra Apache Packages) #258

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ apache_create_vhosts: true
apache_vhosts_filename: "vhosts.conf"
apache_vhosts_template: "vhosts.conf.j2"

# Additional packages to install on Debian/Ubuntu.
apache_packages_extra: []

# On Debian/Ubuntu, a default virtualhost is included in Apache's configuration.
# Set this to `true` to remove that default.
apache_remove_default_vhost: false
Expand All @@ -24,6 +27,8 @@ apache_vhosts:

apache_allow_override: "All"
apache_options: "-Indexes +FollowSymLinks"
apache_directory_index: "index.php index.html"
apache_directory_list: []

apache_vhosts_ssl: []
# Additional properties:
Expand Down Expand Up @@ -60,3 +65,14 @@ apache_restart_state: restarted
# Apache package state; use `present` to make sure it's installed, or `latest`
# if you want to upgrade or switch versions using a new repo.
apache_packages_state: present

# Apache MPM module configuration.
# MPM module to use. Recommended values: `prefork` or `worker`

apache_mpm: true

apache_mpm_module: "prefork"

apache_mpm_template: "mpm.conf.j2"

apache_mpm_config: []
24 changes: 17 additions & 7 deletions tasks/configure-Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
with_items: "{{ apache_ports_configuration_items }}"
notify: restart apache

- name: Disable Apache mods.
file:
path: "{{ apache_server_root }}/mods-enabled/{{ item }}.load"
state: absent
with_items: "{{ apache_mods_disabled }}"
notify: restart apache

- name: Enable Apache mods.
file:
src: "{{ apache_server_root }}/mods-available/{{ item }}.load"
Expand All @@ -18,13 +25,6 @@
with_items: "{{ apache_mods_enabled }}"
notify: restart apache

- name: Disable Apache mods.
file:
path: "{{ apache_server_root }}/mods-enabled/{{ item }}.load"
state: absent
with_items: "{{ apache_mods_disabled }}"
notify: restart apache

- name: Check whether certificates defined in vhosts exist.
stat: "path={{ item.certificate_file }}"
register: apache_ssl_certificates
Expand Down Expand Up @@ -57,3 +57,13 @@
state: absent
notify: restart apache
when: apache_remove_default_vhost

- name: Update MPM settings.
template:
src: "{{ apache_mpm_template }}"
dest: "{{ apache_conf_path }}/mods-available/mpm_{{ apache_mpm_module }}.conf"
owner: root
group: root
mode: 0644
notify: restart apache
when: apache_mpm | bool
14 changes: 7 additions & 7 deletions tasks/configure-RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
with_items: "{{ apache_vhosts_ssl }}"
no_log: "{{ apache_ssl_no_log }}"

- name: Disable Apache mods
file:
path: "{{ apache_server_root }}/conf.modules.d/99-ansible-{{ item }}.conf"
state: absent
with_items: "{{ apache_mods_disabled }}"
notify: restart apache

- name: Enable Apache mods.
copy:
dest: "{{ apache_server_root }}/conf.modules.d/99-ansible-{{ item }}.conf"
Expand All @@ -24,13 +31,6 @@
with_items: "{{ apache_mods_enabled }}"
notify: restart apache

- name: Disable Apache mods
file:
path: "{{ apache_server_root }}/conf.modules.d/99-ansible-{{ item }}.conf"
state: absent
with_items: "{{ apache_mods_disabled }}"
notify: restart apache

- name: Add apache vhosts configuration.
template:
src: "{{ apache_vhosts_template }}"
Expand Down
5 changes: 5 additions & 0 deletions tasks/setup-Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@

- name: Ensure Apache is installed on Debian.
apt: "name={{ apache_packages }} state={{ apache_packages_state }}"

- name: Ensure Apache packages are installed on Debian
apt: "name={{ item.package }} state={{ item.state }}"
loop: "{{ apache_packages_extra }}"
when: apache_packages_extra is defined and apache_packages_extra | length > 0
11 changes: 11 additions & 0 deletions templates/mpm.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# {{ ansible_managed }}

<IfModule mpm_{{ apache_mpm_module }}_module>

{% for mpm in apache_mpm_config %}

{{ mpm.name }} {{ mpm.value }}

{% endfor %}

</IfModule>
50 changes: 50 additions & 0 deletions templates/vhosts.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,43 @@
{% if vhost.serveradmin is defined %}
ServerAdmin {{ vhost.serveradmin }}
{% endif %}

{% if vhost.documentroot is defined %}
<Directory "{{ vhost.documentroot }}">
AllowOverride {{ vhost.allow_override | default(apache_allow_override) }}
Options {{ vhost.options | default(apache_options) }}
{% if vhost.directory_index is defined %}
DirectoryIndex {{ vhost.directory_index | default(apache_directory_index) }}
{% endif %}
{% if apache_vhosts_version == "2.2" %}
Order allow,deny
Allow from all
{% else %}
Require all granted
{% endif %}
</Directory>
{% endif %}

{% if vhost.directory_list is defined -%}
{% for directory in vhost.directory_list %}
<Directory "{{ directory.path }}">
{% if directory.allow_override is defined %}
AllowOverride {{ directory.allow_override }}
{% endif %}

{% if directory.options is defined %}
Options {{ directory.options }}
{% endif %}
{% if apache_vhosts_version == "2.2" %}
Order allow,deny
Allow from all
{% else %}
Require all granted
{% endif %}
</Directory>
{% endfor %}
{% endif %}

{% if vhost.extra_parameters is defined %}
{{ vhost.extra_parameters | indent(width=2, first=True) }}
{% endif %}
Expand Down Expand Up @@ -61,18 +86,43 @@
{% if vhost.serveradmin is defined %}
ServerAdmin {{ vhost.serveradmin }}
{% endif %}

{% if vhost.documentroot is defined %}
<Directory "{{ vhost.documentroot }}">
AllowOverride {{ vhost.allow_override | default(apache_allow_override) }}
Options {{ vhost.options | default(apache_options) }}
{% if vhost.directory_index is defined %}
DirectoryIndex {{ vhost.directory_index | default(apache_directory_index) }}
{% endif %}
{% if apache_vhosts_version == "2.2" %}
Order allow,deny
Allow from all
{% else %}
Require all granted
{% endif %}
</Directory>
{% endif %}

{% if vhost.directory_list is defined -%}
{% for directory in vhost.directory_list %}
<Directory "{{ directory.path }}">
{% if directory.allow_override is defined %}
AllowOverride {{ directory.allow_override }}
{% endif %}

{% if directory.options is defined %}
Options {{ directory.options }}
{% endif %}
{% if apache_vhosts_version == "2.2" %}
Order allow,deny
Allow from all
{% else %}
Require all granted
{% endif %}
</Directory>
{% endfor %}
{% endif %}

{% if vhost.extra_parameters is defined %}
{{ vhost.extra_parameters | indent(width=2, first=True) }}
{% endif %}
Expand Down