From 363df02985bcd22fc613a4c91c9f8d7efcf96827 Mon Sep 17 00:00:00 2001 From: Hector Castro Date: Mon, 13 Oct 2014 10:38:02 -0400 Subject: [PATCH] Add support to customize ports Sometimes it is necessary to alter the ports Apache listens for connections on. Defaults (`80` and `443` for SSL) are preserved, but if you do need to override, `apache_port` and `apache_ssl_port` have been added. --- README.md | 2 ++ defaults/main.yml | 2 ++ tasks/main.yml | 5 +++++ templates/ports.conf.j2 | 15 +++++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 templates/ports.conf.j2 diff --git a/README.md b/README.md index f953e46..d475ad6 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ An Ansible role for installing the Apache web server. - `apache_version` - Apache version - `apache_delete_default_site` - Whether or not to delete the default Apache site (default: `False`) +- `apache_port` - Default port for Apache to listen on (default: `80`) +- `apache_ssl_port` - Default port for Apache to listen for SSL on (default: `443`) ## Example Playbook diff --git a/defaults/main.yml b/defaults/main.yml index 09889fb..7d503a2 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,5 @@ --- apache_version: "2.4.7-1ubuntu4.1" apache_delete_default_site: False +apache_port: 80 +apache_ssl_port: 443 diff --git a/tasks/main.yml b/tasks/main.yml index 7d91c78..2e58a56 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,6 +2,11 @@ - name: Install Apache apt: pkg=apache2={{ apache_version }} state=present +- name: Configure Apache + template: src=ports.conf.j2 dest=/etc/apache2/ports.conf + notify: + - Restart Apache + - name: Delete default site command: a2dissite 000-default register: a2dissite diff --git a/templates/ports.conf.j2 b/templates/ports.conf.j2 new file mode 100644 index 0000000..6e9fe7f --- /dev/null +++ b/templates/ports.conf.j2 @@ -0,0 +1,15 @@ +# If you just change the port or add more ports here, you will likely also +# have to change the VirtualHost statement in +# /etc/apache2/sites-enabled/000-default.conf + +Listen {{ apache_port }} + + + Listen {{ apache_ssl_port }} + + + + Listen {{ apache_ssl_port }} + + +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet