Skip to content

Commit

Permalink
Add support to customize ports
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hector Castro committed Oct 13, 2014
1 parent 28f7c20 commit 363df02
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---
apache_version: "2.4.7-1ubuntu4.1"
apache_delete_default_site: False
apache_port: 80
apache_ssl_port: 443
5 changes: 5 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions templates/ports.conf.j2
Original file line number Diff line number Diff line change
@@ -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 }}

<IfModule ssl_module>
Listen {{ apache_ssl_port }}
</IfModule>

<IfModule mod_gnutls.c>
Listen {{ apache_ssl_port }}
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

0 comments on commit 363df02

Please sign in to comment.