From da0794ed737cf7af0daa729582d65a128bbd329c Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 14 Oct 2015 18:22:30 +0200 Subject: [PATCH] library/roles/apache: Change the playbook to install and enable the mpm_worker as default. Manage enabling/disabling the service. --- apache/defaults/main.yml | 13 ++++++++++++- apache/handlers/main.yml | 3 +++ apache/tasks/apache.yml | 20 ++++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/apache/defaults/main.yml b/apache/defaults/main.yml index 11202f9d..7dc26445 100644 --- a/apache/defaults/main.yml +++ b/apache/defaults/main.yml @@ -1,15 +1,26 @@ --- +apache_service_enabled: True apache_user: www-data apache_group: '{{ apache_user }}' +# Possible choices: event, prefork (the old ones), worker (the threaded version), itm +apache_mpm_mode: worker + apache_packages: - apache2 - - apache2-mpm-prefork + - 'apache2-mpm-{{ apache_mpm_mode }}' - apache2-utils - libapache2-mod-xsendfile - unzip - zip +# Only one can be present at the same time. It needs to be listed as the last one +apache_worker_modules: +# - { name: 'mpm_itm', state: 'absent' } + - { name: 'mpm_event', state: 'absent' } + - { name: 'mpm_prefork', state: 'absent' } + - { name: 'mpm_{{ apache_mpm_mode }}', state: 'present' } + apache_default_modules: - headers - rewrite diff --git a/apache/handlers/main.yml b/apache/handlers/main.yml index 6991f5c3..a4fd00ab 100644 --- a/apache/handlers/main.yml +++ b/apache/handlers/main.yml @@ -2,3 +2,6 @@ - name: apache2 reload service: name=apache2 state=reloaded +- name: apache2 restart + service: name=apache2 state=restarted + diff --git a/apache/tasks/apache.yml b/apache/tasks/apache.yml index b984f8ea..f137be6c 100644 --- a/apache/tasks/apache.yml +++ b/apache/tasks/apache.yml @@ -2,13 +2,19 @@ - name: Install the apache packages apt: pkg={{ item }} state=installed force=yes with_items: apache_packages - tags: apache + tags: [ 'apache', 'apache_main_packages' ] + +- name: Load the required worker module + apache2_module: name={{ item.name }} state={{ item.state }} + with_items: apache_worker_modules + notify: apache2 restart + tags: [ 'apache', 'apache_modules', 'apache_workers_modules' ] - name: Load the required modules apache2_module: name={{ item }} state=present with_items: apache_default_modules notify: apache2 reload - tags: apache + tags: [ 'apache', 'apache_modules' ] - name: Remove the default virtualhost file file: dest=/etc/apache2/sites-enabled/{{ item }} state=absent @@ -17,3 +23,13 @@ - 000-default.conf notify: apache2 reload tags: apache + +- name: Ensure that the apache service is enabled and started + service: name=apache2 state=started enabled=yes + when: apache_service_enabled + tags: apache + +- name: Ensure that the apache service is disabled and stopped if we do not want it running + service: name=apache2 state=stopped enabled=no + when: not apache_service_enabled + tags: apache