mirror of
https://github.com/geerlingguy/ansible-role-apache
synced 2024-12-22 11:00:18 +01:00
Issue #14: Fix Apache version detection and related configuration for more flexibility.
This commit is contained in:
parent
aff1f3a524
commit
d687bb21c5
10 changed files with 85 additions and 91 deletions
|
@ -11,3 +11,5 @@ apache_create_vhosts: true
|
||||||
apache_vhosts:
|
apache_vhosts:
|
||||||
# Additional properties: 'serveradmin, extra_parameters'.
|
# Additional properties: 'serveradmin, extra_parameters'.
|
||||||
- {servername: "local.dev", documentroot: "/var/www/html"}
|
- {servername: "local.dev", documentroot: "/var/www/html"}
|
||||||
|
|
||||||
|
apache_vhosts_version: "2.2"
|
||||||
|
|
33
tasks/configure-Debian.yml
Normal file
33
tasks/configure-Debian.yml
Normal 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
|
19
tasks/configure-RedHat.yml
Normal file
19
tasks/configure-RedHat.yml
Normal 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
|
|
@ -1,32 +1,42 @@
|
||||||
---
|
---
|
||||||
|
# Include variables and define needed variables.
|
||||||
- name: Include OS-specific variables.
|
- name: Include OS-specific variables.
|
||||||
include_vars: "{{ ansible_os_family }}.yml"
|
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.
|
- name: Define apache_packages.
|
||||||
set_fact:
|
set_fact:
|
||||||
apache_packages: "{{ __apache_packages | list }}"
|
apache_packages: "{{ __apache_packages | list }}"
|
||||||
when: apache_packages is not defined
|
when: apache_packages is not defined
|
||||||
|
|
||||||
|
# Setup/install tasks.
|
||||||
- include: setup-RedHat.yml
|
- include: setup-RedHat.yml
|
||||||
when: ansible_os_family == 'RedHat'
|
when: ansible_os_family == 'RedHat'
|
||||||
|
|
||||||
- include: setup-Debian.yml
|
- include: setup-Debian.yml
|
||||||
when: ansible_os_family == 'Debian'
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
- name: Add apache vhosts configuration.
|
# Figure out what version of Apache is installed.
|
||||||
template:
|
- name: Get installed version of Apache.
|
||||||
src: "vhosts-{{ apache_vhosts_version }}.conf.j2"
|
command: "{{ apache_daemon }} -v"
|
||||||
dest: "{{ apache_conf_path }}/vhosts.conf"
|
changed_when: false
|
||||||
owner: root
|
register: _apache_version
|
||||||
group: root
|
|
||||||
mode: 0644
|
- name: Create apache_version variable.
|
||||||
notify: restart apache
|
set_fact:
|
||||||
when: apache_create_vhosts
|
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.
|
- name: Ensure Apache is started and enabled on boot.
|
||||||
service:
|
service:
|
||||||
|
|
|
@ -5,36 +5,3 @@
|
||||||
- name: Ensure Apache is installed.
|
- name: Ensure Apache is installed.
|
||||||
apt: "name={{ item }} state=installed"
|
apt: "name={{ item }} state=installed"
|
||||||
with_items: apache_packages
|
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
|
|
||||||
|
|
|
@ -5,12 +5,3 @@
|
||||||
state: installed
|
state: installed
|
||||||
enablerepo: "{{ apache_enablerepo }}"
|
enablerepo: "{{ apache_enablerepo }}"
|
||||||
with_items: apache_packages
|
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
|
|
||||||
|
|
|
@ -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 }}"
|
|
||||||
}
|
|
|
@ -2,13 +2,11 @@
|
||||||
apache_daemon: apache2
|
apache_daemon: apache2
|
||||||
apache_server_root: /etc/apache2
|
apache_server_root: /etc/apache2
|
||||||
apache_conf_path: /etc/apache2
|
apache_conf_path: /etc/apache2
|
||||||
apache_vhosts_version: "2.4"
|
|
||||||
|
|
||||||
__apache_packages:
|
__apache_packages:
|
||||||
- apache2
|
- apache2
|
||||||
- apache2-mpm-prefork
|
- apache2-mpm-prefork
|
||||||
- apache2-utils
|
- apache2-utils
|
||||||
- apache2-bin
|
|
||||||
|
|
||||||
apache_ports_configuration_items:
|
apache_ports_configuration_items:
|
||||||
- {
|
- {
|
|
@ -1,16 +1,5 @@
|
||||||
---
|
---
|
||||||
apache_daemon: apache2
|
|
||||||
apache_server_root: /etc/apache2
|
|
||||||
apache_conf_path: /etc/apache2
|
|
||||||
apache_vhosts_version: "2.2"
|
apache_vhosts_version: "2.2"
|
||||||
|
|
||||||
__apache_packages:
|
|
||||||
- apache2
|
|
||||||
- apache2-mpm-prefork
|
|
||||||
- apache2-utils
|
|
||||||
- apache2.2-bin
|
|
||||||
- apache2.2-common
|
|
||||||
|
|
||||||
apache_ports_configuration_items:
|
apache_ports_configuration_items:
|
||||||
- {
|
- {
|
||||||
regexp: "^Listen ",
|
regexp: "^Listen ",
|
7
vars/apache-24.yml
Normal file
7
vars/apache-24.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
apache_vhosts_version: "2.4"
|
||||||
|
apache_ports_configuration_items:
|
||||||
|
- {
|
||||||
|
regexp: "^Listen ",
|
||||||
|
line: "Listen {{ apache_listen_port }}"
|
||||||
|
}
|
Loading…
Reference in a new issue