Create vhosts, users, and document roots

This commit is contained in:
Jason Rothstein 2021-10-25 21:41:35 -05:00
parent d92c35b296
commit 4afbe76369
4 changed files with 149 additions and 1 deletions

View File

@ -11,7 +11,21 @@ Any pre-requisites that may not be covered by Ansible itself or the role should
Role Variables Role Variables
-------------- --------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. * main variable of type list
* http_vhost
* required dictionary elements
* fqdn : The FQDN of the website
* optional dictionary elements
* aliases : list of alternative FQDN for the website
* proxy : URL to direct traffic for the FQDN to, e.g. http://localhost:8080
~~~
http_vhost:
- fqdn: 'www.example.com'
aliases:
- 'exmaple.com'
proxy: 'http://localhost:8080'
~~~
Dependencies Dependencies
------------ ------------

View File

@ -114,6 +114,33 @@
loop: '{{ ensure_apache.firewall_list }}' loop: '{{ ensure_apache.firewall_list }}'
loop_control: loop_control:
label: '{{ item.service }} will be {{ item.state }}' label: '{{ item.service }} will be {{ item.state }}'
- name: 'ensure users'
when:
- ansible_system == 'Linux'
- ensure_apache is defined
- http_vhost is defined
- http_vhost is iterable
ansible.builtin.user:
name: '{{ item.fqdn }}'
loop: '{{ http_vhost }}'
loop_control:
label: '{{ item.fqdn }} will be ensured'
- name: 'ensure vhost document roots'
when:
- ansible_system == 'Linux'
- ensure_apache is defined
- http_vhost is defined
- http_vhost is iterable
ansible.builtin.file:
group: '{{ item.fqdn }}'
owner: '{{ item.fqdn }}'
mode: '2775'
path: '/srv/http/{{ item.fqdn }}'
state: 'directory'
setype: 'httpd_sys_content_t'
loop: '{{ http_vhost }}'
loop_control:
label: '/srv/http/{{ item.fqdn }} will be ensured'
- name: 'ensure services' - name: 'ensure services'
when: when:
- ansible_system == 'Linux' - ansible_system == 'Linux'

View File

@ -0,0 +1,102 @@
<Directory "/srv/http">
AllowOverride None
Require all granted
</Directory>
{% for item in http_vhost %}
<Directory "/srv/http/{{ item.fqdn }}">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
{% endfor %}
{% for item in http_vhost %}
{% if item.aliases is defined %}
{% for item_alias in item.aliases %}
<VirtualHost *:80>
ServerName {{ item_alias }}
ServerAdmin webmaster@firedragonenterprises.com
DocumentRoot /srv/http/{{ item.fqdn }}
RedirectMatch permanent "^(?!/\.well-known/acme-challenge/).*" https://{{ item.fqdn }}$0
</VirtualHost>
{% endfor %}
{% endif %}
<VirtualHost *:80>
ServerName {{ item.fqdn }}
ServerAdmin webmaster@firedragonenterprises.com
DocumentRoot /srv/http/{{ item.fqdn }}
RedirectMatch permanent "^(?!/\.well-known/acme-challenge/).*" https://{{ item.fqdn }}$0
</VirtualHost>
{% if item.aliases is defined %}
{% for item_alias in item.aliases %}
<VirtualHost *:443>
SSLEngine on
SSLProtocol all -TLSv1.1
SSLProxyProtocol all -TLSv1.1
SSLHonorCipherOrder on
SSLCipherSuite PROFILE=SYSTEM
SSLProxyCipherSuite PROFILE=SYSTEM
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
ServerName {{ item_alias }}
ServerAdmin webmaster@firedragonenterprises.com
DocumentRoot /srv/http/{{ item.fqdn }}
RedirectMatch permanent "^(?!/\.well-known/acme-challenge/).*" https://{{ item.fqdn }}$0
<Location /.ansible>
Require all denied
</Location>
<Location /.config>
Require all denied
</Location>
<Location /.ssh>
Require all denied
</Location>
</VirtualHost>
{% endfor %}
{% endif %}
<VirtualHost *:443>
SSLEngine on
SSLProtocol all -TLSv1.1
SSLProxyProtocol all -TLSv1.1
SSLHonorCipherOrder on
SSLCipherSuite PROFILE=SYSTEM
SSLProxyCipherSuite PROFILE=SYSTEM
# SSLCertificateFile /etc/pki/tls/certs/localhost.crt
# SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
ServerName {{ item.fqdn }}
ServerAdmin webmaster@firedragonenterprises.com
DocumentRoot /srv/http/{{ item.fqdn }}
Alias /error/ "/var/www/error/"
{% if item.proxy is defined %}
ProxyPass "/.well-known" "!"
ProxyPass "/phpMyAdmin" "!"
ProxyPass "/phpmyadmin" "!"
ProxyPass "/" "{{ item.proxy }}"
ProxyPassReverse "/" "{{ item.proxy }}"
ProxyTimeout 300
{% endif %}
<Location /.ansible>
Require all denied
</Location>
<Location /.cache>
Require all denied
</Location>
<Location /.config>
Require all denied
</Location>
<Location /.local>
Require all denied
</Location>
<Location /.git>
Require all denied
</Location>
<Location /.ssh>
Require all denied
</Location>
</VirtualHost>
{% endfor %}

View File

@ -39,6 +39,11 @@ template_list:
mode: '0644' mode: '0644'
owner: 'root' owner: 'root'
src: '{{ ansible_distribution }}/{{ ansible_distribution_major_version }}/etc/httpd/conf.d/README' src: '{{ ansible_distribution }}/{{ ansible_distribution_major_version }}/etc/httpd/conf.d/README'
- dest: '/etc/httpd/conf.d/vhost.conf'
group: 'root'
mode: '0644'
owner: 'root'
src: '{{ ansible_distribution }}/{{ ansible_distribution_major_version }}/etc/httpd/conf.d/vhost.conf'
- dest: '/etc/httpd/conf.d/ssl.conf' - dest: '/etc/httpd/conf.d/ssl.conf'
group: 'root' group: 'root'
mode: '0644' mode: '0644'