An Ansible role to configure Apache virtual host.
The role does these:
- Creates and activates a virtual host with Apache.
- Doesn't configure HTTPS. You can use https://letsencrypt.org/ for that.
The role is available on Ansible Galaxy: https://galaxy.ansible.com/wahidsadik/apache-virtual-host.
To add this role from Ansible Galaxy, run: ansible-galaxy install wahidsadik.apache-virtual-host
.
To add this from your Ansible requirements.yml
, add this to the file:
src: wahidsadik.apache-virtual-host
The remote_user
needs to have sudo
access or be root
equivalent user.
The role defines the following variables in defaults/main.yml
:
Variable name | Default value | Comment |
---|---|---|
add_www |
false |
When true , www will be added as server alias. |
disable_default_site |
false |
When true , default site code will be removed and virtual host will be deactivated. |
letsencrypt_tls |
false |
When true , certbot will be used to create TLS certificate. Also see certbot_tos_email variable below. |
Users must pass the following parameters (i.e. variables):
website
. It is assumed that the website assets will be available at/var/www/{{website}}
location.template
: Choice ofbasic
,laravel
andrelative
.basic
sets document-root to/var/www/{{website}}
.laravel
sets document-root to/var/www/{{website}}/public
.relative
sets document-root to/var/www/{{website}}/{{relative_path}}
.- Requires additional definition of
relative_path
.
- Requires additional definition of
certbot_tos_email
: Whenletsencrypt_tls
istrue
, this should be provided. Email address.
Example values for domain
:
- example.com
- abc
- #1 - When
letsencrypt_tls
ostrue
, the role generates only one TLS certificate even whenadd_www
istrue
. As as result,https://www.example.com
will get an invalid certificate error.
Apache2 must be installed on the hosts.
Example 1: Simplest example with minimum variable passing
- hosts: servers
remote_user: root
roles:
- {
role: wahidsadik.ansible-role-apache,
website: example.com,
template: basic
}
Example 2: With sudo and minimum variable passing
- hosts: servers
remote_user: deployer
become: true
become_method: sudo
roles:
- {
role: wahidsadik.ansible-role-apache,
website: example.com,
template: laravel
}
MIT
Wahid Sadik. More at: https://wahidsadik.github.io.