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

Add support for apache_listen_port_ssl for Debian, RedHat, Suse and AmazonLinux. #150

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 5 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apache_enablerepo: ""

apache_listen_ip: "*"
apache_listen_port: 80
# supported on Debian, RedHat/Amazon Linux and SUSE
apache_listen_port_ssl: 443

apache_create_vhosts: true
Expand Down Expand Up @@ -40,10 +41,11 @@ apache_ignore_missing_ssl_certificate: true
apache_ssl_protocol: "All -SSLv2 -SSLv3"
apache_ssl_cipher_suite: "AES256+EECDH:AES256+EDH"

# Only used on Debian/Ubuntu.
# Only used on Debian, RedHat and SUSE based OS.
# You can use either the old format of this role (e.g. rewrite.role) or use mod name as below
apache_mods_enabled:
- rewrite.load
- ssl.load
- rewrite
- ssl
apache_mods_disabled: []

# Set initial apache state. Recommended values: `started` or `stopped`
Expand Down
23 changes: 16 additions & 7 deletions tasks/configure-Debian.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
---
- name: Configure Apache.
- name: Configure Apache (lineinfile - legacy).
lineinfile:
dest: "{{ apache_server_root }}/ports.conf"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
with_items: "{{ apache_ports_configuration_items }}"
when: item.line is defined
notify: restart apache

- name: Configure Apache (replace).
replace:
path: "{{ apache_server_root }}/ports.conf"
regexp: "{{ item.regexp }}"
replace: "{{ item.replace }}"
with_items: "{{ apache_ports_configuration_items }}"
when: item.replace is defined
notify: restart apache

- name: Enable Apache mods.
file:
src: "{{ apache_server_root }}/mods-available/{{ item }}"
dest: "{{ apache_server_root }}/mods-enabled/{{ item }}"
state: link
apache2_module:
name: "{{ item | regex_replace('(\\w+)\\.load','\\1') }}"
state: present
with_items: "{{ apache_mods_enabled }}"
notify: restart apache

- name: Disable Apache mods.
file:
path: "{{ apache_server_root }}/mods-enabled/{{ item }}"
apache2_module:
name: "{{ item | regex_replace('(\\w+)\\.load','\\1') }}"
state: absent
with_items: "{{ apache_mods_disabled }}"
notify: restart apache
Expand Down
33 changes: 32 additions & 1 deletion tasks/configure-RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
---
- name: Configure Apache.
- name: Install SELinux Python dependencies.
package:
name: libselinux-python
state: present

- name: Enable Apache mods.
apache2_module:
name: "{{ item | regex_replace('(\\w+)\\.load','\\1') }}"
state: present
with_items: "{{ apache_mods_enabled }}"
notify: restart apache

- name: Disable Apache mods.
apache2_module:
name: "{{ item | regex_replace('(\\w+)\\.load','\\1') }}"
state: absent
with_items: "{{ apache_mods_disabled }}"
notify: restart apache

- name: Configure Apache httpd.conf (lineinfile - legacy).
lineinfile:
dest: "{{ apache_server_root }}/conf/{{ apache_daemon }}.conf"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
with_items: "{{ apache_ports_configuration_items }}"
when: item.line is defined
notify: restart apache

- name: Configure Apache ssl.conf (replace).
replace:
dest: "{{ apache_server_root }}/conf.d/ssl.conf"
regexp: "{{ item.regexp }}"
replace: "{{ item.replace }}"
with_items: "{{ apache_ports_configuration_items }}"
when:
- item.replace is defined
- '"ssl.load" in apache_mods_enabled or "ssl" in apache_mods_enabled'
notify: restart apache

- name: Check whether certificates defined in vhosts exist.
Expand Down
3 changes: 2 additions & 1 deletion tasks/configure-Solaris.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
- name: Configure Apache.
- name: Configure Apache httpd.conf (lineinfile - legacy).
lineinfile:
dest: "{{ apache_server_root }}/{{ apache_daemon }}.conf"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
with_items: "{{ apache_ports_configuration_items }}"
when: item.line is defined
notify: restart apache

- name: Add apache vhosts configuration.
Expand Down
26 changes: 25 additions & 1 deletion tasks/configure-Suse.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
---
- name: Configure Apache.
- name: Configure Apache (lineinfile - legacy).
lineinfile:
dest: "{{ apache_server_root }}/listen.conf"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
with_items: "{{ apache_ports_configuration_items }}"
when: item.line is defined
notify: restart apache

- name: Configure Apache (replace).
replace:
path: "{{ apache_server_root }}/listen.conf"
regexp: "{{ item.regexp }}"
replace: "{{ item.replace }}"
with_items: "{{ apache_ports_configuration_items }}"
when: item.replace is defined
notify: restart apache

- name: Enable Apache mods.
apache2_module:
name: "{{ item | regex_replace('(\\w+)\\.load','\\1') }}"
state: present
with_items: "{{ apache_mods_enabled }}"
notify: restart apache

- name: Disable Apache mods.
apache2_module:
name: "{{ item | regex_replace('(\\w+)\\.load','\\1') }}"
state: absent
with_items: "{{ apache_mods_disabled }}"
notify: restart apache

- name: Check whether certificates defined in vhosts exist.
Expand Down
10 changes: 3 additions & 7 deletions vars/AmazonLinux.yml → vars/Amazon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ apache_conf_path: /etc/httpd/conf.d
apache_vhosts_version: "2.4"

__apache_packages:
- httpd24
- httpd24-devel
- mod24_ssl
- httpd
- httpd-devel
- mod_ssl
- openssh

apache_ports_configuration_items:
- regexp: "^Listen "
line: "Listen {{ apache_listen_port }}"
6 changes: 1 addition & 5 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ apache_conf_path: /etc/apache2

__apache_packages:
- apache2
- apache2-utils

apache_ports_configuration_items:
- regexp: "^Listen "
line: "Listen {{ apache_listen_port }}"
- apache2-utils
6 changes: 0 additions & 6 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,3 @@ __apache_packages:
- httpd-devel
- mod_ssl
- openssh

apache_ports_configuration_items:
- regexp: "^Listen "
line: "Listen {{ apache_listen_port }}"
- regexp: "^#?NameVirtualHost "
line: "NameVirtualHost {{ apache_listen_ip }}:{{ apache_listen_port }}"
6 changes: 0 additions & 6 deletions vars/Solaris.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,3 @@ __apache_packages:
- web/server/apache-24
- web/server/apache-24/module/apache-ssl
- web/server/apache-24/module/apache-security

apache_ports_configuration_items:
- regexp: "^Listen "
line: "Listen {{ apache_listen_port }}"
- regexp: "^#?NameVirtualHost "
line: "NameVirtualHost {{ apache_listen_ip }}:{{ apache_listen_port }}"
12 changes: 3 additions & 9 deletions vars/Suse.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
---
apache_service: apache2
apache_daemon: httpd2
apache_daemon: httpd
apache_daemon_path: /usr/sbin/
apache_server_root: /etc/apache2
apache_conf_path: /etc/apache2/conf.d

apache_vhosts_version: "2.2"
apache_vhosts_version: "2.4"

__apache_packages:
- apache2
- openssh

apache_ports_configuration_items:
- regexp: "^Listen "
line: "Listen {{ apache_listen_port }}"
- regexp: "^#?NameVirtualHost "
line: "NameVirtualHost {{ apache_listen_ip }}:{{ apache_listen_port }}"
- openssh
15 changes: 14 additions & 1 deletion vars/apache-22.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
---
apache_vhosts_version: "2.2"
apache_default_vhost_filename: 000-default

apache_ports_configuration_items:
# Debian, Ubuntu and RedHat
- {
regexp: "^Listen ",
regexp: "^Listen\\s+\\d+$",
line: "Listen {{ apache_listen_port }}"
}
# Debian/Ubuntu
- {
regexp: "^#?NameVirtualHost ",
line: "NameVirtualHost {{ apache_listen_ip }}:{{ apache_listen_port }}"
}
# Debian/Ubuntu (SSL)
- {
regexp: "^(<IfModule\\s+.+>(?:\\n+\\s+#.+)*\\s+)Listen\\s+\\d+$",
replace: "\\1Listen {{ apache_listen_port_ssl }}"
}
# RedHat/CentOS 6 (SSL)
- {
regexp: "^(LoadModule\\s+ssl_module\\s+.*(?:\\n.*)*)Listen\\s+\\d+$",
replace: "\\1Listen {{ apache_listen_port_ssl }}"
}
21 changes: 19 additions & 2 deletions vars/apache-24.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
---
apache_vhosts_version: "2.4"
apache_default_vhost_filename: 000-default.conf

apache_ports_configuration_items:
# Debian/Ubuntu and RedHat/CentOS/Amazon Linux Regex for http
- {
regexp: "^Listen ",
line: "Listen {{ apache_listen_port }}"
regexp: "^Listen\\s+\\d+$",
line: "Listen {{ apache_listen_port }}"
}
# RedHat/CentOS 7, Amazon Linux
- {
regexp: "^Listen\\s+\\d+\\s+https$",
replace: "Listen {{ apache_listen_port_ssl }} https"
}
# Debian, SUSE
- {
regexp: "^(\\s*<IfModule\\s+.+>(?:\\n+\\s+#.+)*\\s+)Listen\\s+\\d+",
replace: "\\1Listen {{ apache_listen_port_ssl }}"
}
# SUSE
- {
regexp: "^(# - name-based virtual hosting:\\n(?:#\\n)*)#?\\s*NameVirtualHost\\s+.*:\\d+",
replace: "\\1NameVirtualHost {{ apache_listen_ip }}:{{ apache_listen_port }}"
}