Issue #14: Fix Apache version detection and related configuration for more flexibility.

This commit is contained in:
Jeff Geerling 2014-10-22 13:41:14 -05:00
parent aff1f3a524
commit d687bb21c5
10 changed files with 85 additions and 91 deletions

View file

@ -11,3 +11,5 @@ apache_create_vhosts: true
apache_vhosts:
# Additional properties: 'serveradmin, extra_parameters'.
- {servername: "local.dev", documentroot: "/var/www/html"}
apache_vhosts_version: "2.2"

View file

@ -0,0 +1,33 @@
---
- name: Configure Apache.
lineinfile:
dest: "{{ apache_server_root }}/ports.conf"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
with_items: apache_ports_configuration_items
notify: restart apache
- name: Enable Apache mods.
file:
src: "{{ apache_server_root }}/mods-available/{{ item }}"
dest: "{{ apache_server_root }}/mods-enabled/{{ item }}"
state: link
with_items: apache_mods_enabled
notify: restart apache
- name: Add apache vhosts configuration.
template:
src: "vhosts-{{ apache_vhosts_version }}.conf.j2"
dest: "{{ apache_conf_path }}/sites-available/vhosts.conf"
owner: root
group: root
mode: 0644
notify: restart apache
when: apache_create_vhosts
- name: Add vhost symlink in sites-enabled.
file:
src: "{{ apache_conf_path }}/sites-available/vhosts.conf"
dest: "{{ apache_conf_path }}/sites-enabled/vhosts.conf"
state: link

View file

@ -0,0 +1,19 @@
---
- name: Configure Apache.
lineinfile:
dest: "{{ apache_server_root }}/conf/{{ apache_daemon }}.conf"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
with_items: apache_ports_configuration_items
notify: restart apache
- name: Add apache vhosts configuration.
template:
src: "vhosts-{{ apache_vhosts_version }}.conf.j2"
dest: "{{ apache_conf_path }}/vhosts.conf"
owner: root
group: root
mode: 0644
notify: restart apache
when: apache_create_vhosts

View file

@ -1,32 +1,42 @@
---
# Include variables and define needed variables.
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
when: ansible_os_family == 'RedHat'
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}-{{ ansible_lsb.codename }}.yml"
when: ansible_os_family == 'Debian'
- name: Define apache_packages.
set_fact:
apache_packages: "{{ __apache_packages | list }}"
when: apache_packages is not defined
# Setup/install tasks.
- include: setup-RedHat.yml
when: ansible_os_family == 'RedHat'
- include: setup-Debian.yml
when: ansible_os_family == 'Debian'
- name: Add apache vhosts configuration.
template:
src: "vhosts-{{ apache_vhosts_version }}.conf.j2"
dest: "{{ apache_conf_path }}/vhosts.conf"
owner: root
group: root
mode: 0644
notify: restart apache
when: apache_create_vhosts
# Figure out what version of Apache is installed.
- name: Get installed version of Apache.
command: "{{ apache_daemon }} -v"
changed_when: false
register: _apache_version
- name: Create apache_version variable.
set_fact:
apache_version: "{{ _apache_version.stdout.split()[2].split('/')[1] }}"
- include_vars: apache-22.yml
when: "apache_version.split('.')[1] == '2'"
- include_vars: apache-24.yml
when: "apache_version.split('.')[1] == '4'"
# Configure Apache.
- include: configure-RedHat.yml
when: ansible_os_family == 'RedHat'
- include: configure-Debian.yml
when: ansible_os_family == 'Debian'
- name: Ensure Apache is started and enabled on boot.
service:

View file

@ -5,36 +5,3 @@
- name: Ensure Apache is installed.
apt: "name={{ item }} state=installed"
with_items: apache_packages
- name: Configure Apache.
lineinfile:
dest: "{{ apache_server_root }}/ports.conf"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
with_items: apache_ports_configuration_items
notify: restart apache
- name: Enable Apache mods.
file:
src: "{{ apache_server_root }}/mods-available/{{ item }}"
dest: "{{ apache_server_root }}/mods-enabled/{{ item }}"
state: link
with_items: apache_mods_enabled
notify: restart apache
- name: Add apache vhosts configuration.
template:
src: "vhosts-{{ apache_vhosts_version }}.conf.j2"
dest: "{{ apache_conf_path }}/sites-available/vhosts.conf"
owner: root
group: root
mode: 0644
notify: restart apache
when: apache_create_vhosts
- name: Add vhost symlink in sites-enabled.
file:
src: "{{ apache_conf_path }}/sites-available/vhosts.conf"
dest: "{{ apache_conf_path }}/sites-enabled/vhosts.conf"
state: link

View file

@ -5,12 +5,3 @@
state: installed
enablerepo: "{{ apache_enablerepo }}"
with_items: apache_packages
- name: Configure Apache.
lineinfile:
dest: "{{ apache_server_root }}/conf/{{ apache_daemon }}.conf"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
with_items: apache_ports_configuration_items
notify: restart apache

View file

@ -1,22 +0,0 @@
---
apache_daemon: apache2
apache_server_root: /etc/apache2
apache_conf_path: /etc/apache2
apache_vhosts_version: "2.2"
__apache_packages:
- apache2
- apache2-mpm-prefork
- apache2-utils
- apache2.2-bin
- apache2.2-common
apache_ports_configuration_items:
- {
regexp: "^Listen ",
line: "Listen {{ apache_listen_port }}"
}
- {
regexp: "^NameVirtualHost ",
line: "NameVirtualHost *:{{ apache_listen_port }}"
}

View file

@ -2,13 +2,11 @@
apache_daemon: apache2
apache_server_root: /etc/apache2
apache_conf_path: /etc/apache2
apache_vhosts_version: "2.4"
__apache_packages:
- apache2
- apache2-mpm-prefork
- apache2-utils
- apache2-bin
apache_ports_configuration_items:
- {

View file

@ -1,16 +1,5 @@
---
apache_daemon: apache2
apache_server_root: /etc/apache2
apache_conf_path: /etc/apache2
apache_vhosts_version: "2.2"
__apache_packages:
- apache2
- apache2-mpm-prefork
- apache2-utils
- apache2.2-bin
- apache2.2-common
apache_ports_configuration_items:
- {
regexp: "^Listen ",

7
vars/apache-24.yml Normal file
View file

@ -0,0 +1,7 @@
---
apache_vhosts_version: "2.4"
apache_ports_configuration_items:
- {
regexp: "^Listen ",
line: "Listen {{ apache_listen_port }}"
}