Compare commits

...

11 Commits

Author SHA1 Message Date
7dd6b51c2c duplicate default var defintition 2025-02-19 18:14:26 +01:00
3db2160549 remove dev to apache 2025-02-18 13:54:55 +01:00
dfdae74445 fix modules enabling code 2025-02-18 12:17:49 +01:00
2d4e5a5853 add some modules, include http2 2024-12-19 11:13:13 +01:00
a882c50e2a manual merge 2024-05-23 09:34:31 +02:00
180aa7c404 Merge branch 'certbot' 2024-05-08 17:30:19 +02:00
a0ad2a9301 make it work on debian, restore certificate management 2024-05-08 17:27:37 +02:00
19ed4cd113 make it work on debian
remove certbot generation (its got its own role)
2024-05-07 15:06:02 +02:00
31e9283fc0 readme: separe les variables a modifier des autres 2024-02-08 09:51:31 +01:00
b92dbfcd84 remove test certificates 2023-12-22 15:36:32 +01:00
ffb66f7281 add dep to tco.changelog 2023-10-12 13:27:02 +02:00
12 changed files with 72 additions and 23 deletions

4
ISSUES Normal file
View File

@@ -0,0 +1,4 @@
too many variables
should not take care of ssl, php etc.
ditch it in favor of tco.Webhosting ?

View File

@@ -11,24 +11,24 @@ Obviously an apache server, you'll probably want php and some certificates too.
Role Variables Role Variables
-------------- --------------
apache_db_name: no default
apache_db_password: no default
apache_server_ip
apache_server_name
apache_server_alias (list)
apache_ssl_root_email: email to use for certificate
apache_access_log: {{ apache_base_dir}}/logs/access_log apache_access_log: {{ apache_base_dir}}/logs/access_log
apache_allowoverride: all apache_allowoverride: all
apache_base_dir: /srv/{{ apache_server_name }} apache_base_dir: /srv/{{ apache_server_name }}
apache_db_login_password: from my.cnf apache_db_login_password: from my.cnf
apache_db_login_user: from root/.my.cnf apache_db_login_user: from root/.my.cnf
apache_db_name: no default
apache_db_password: no default
apache_db_user: no default apache_db_user: no default
apache_document_root: {{ apache_base_dir }}/www apache_document_root: {{ apache_base_dir }}/www
apache_php_socket: {{ apache_base_dir }}/php-fpm.sock apache_php_socket: {{ apache_base_dir }}/php-fpm.sock
apache_server_alias (list)
apache_server_ip
apache_server_name
apache_ssl_certificate: /etc/letsencrypt/live/{{ apache_server_name }}/cert.pem apache_ssl_certificate: /etc/letsencrypt/live/{{ apache_server_name }}/cert.pem
apache_ssl_chain: /etc/letsencrypt/live/{{ apache_server_name }}/fullchain.pem apache_ssl_chain: /etc/letsencrypt/live/{{ apache_server_name }}/fullchain.pem
apache_ssl_key: /etc/letsencrypt/live/{{ apache_server_name }}/privkey.pem apache_ssl_key: /etc/letsencrypt/live/{{ apache_server_name }}/privkey.pem
apache_ssl_root_email: email to use for certificate
apache_ssl_root_email: email used for letsencrypt certificate
apache_use_database: false apache_use_database: false
apache_use_dns: true - wether we setup up dns A and CNAME records apache_use_dns: true - wether we setup up dns A and CNAME records
apache_use_php: true apache_use_php: true

View File

@@ -15,3 +15,10 @@ apache_use_ssl: true
apache_use_stats: true apache_use_stats: true
apache_user: "{{ apache_server_name | regex_search( '([^.]+)' ) }}" apache_user: "{{ apache_server_name | regex_search( '([^.]+)' ) }}"
apache_use_database: false apache_use_database: false
apache_modules_list:
- headers
- http2
- rewrite
- proxy
- proxy_http
- proxy_fcgi

View File

@@ -2,8 +2,8 @@
# handlers file for apache_vhost # handlers file for apache_vhost
- name: restart apache - name: restart apache
service: service:
name: httpd name: "{{ apache_service_name }}"
state: restarted state: reloaded
- name: restart zabbix_agentd - name: restart zabbix_agentd
service: service:

View File

@@ -47,7 +47,6 @@ galaxy_info:
# Maximum 20 tags per role. # Maximum 20 tags per role.
dependencies: dependencies:
- role: tconstans.apache - { role: tco.changelog, myrole_name: ansible_apache_vhost }
- { role: tco.changelog, role_version: 1.0, myrole_name: apache_vhost }
# List your role dependencies here, one per line. Be sure to remove the '[]' above, # List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list. # if you add dependencies to this list.

View File

@@ -3,7 +3,7 @@
package: package:
name: name:
- certbot - certbot
- mod_ssl - "{{ apache_ssl_packages }}"
state: present state: present
@@ -12,7 +12,7 @@
apache_use_ssl: false apache_use_ssl: false
template: template:
src: vhost.conf.jj src: vhost.conf.jj
dest: /etc/httpd/conf.d/{{ apache_server_name }}.conf dest: "{{ apache_config_dir }}/{{ apache_server_name }}.conf"
mode: 0644 mode: 0644
notify: restart apache notify: restart apache
register: result register: result
@@ -20,20 +20,20 @@
# cant use meta / flush handlers in conditionnals # cant use meta / flush handlers in conditionnals
- name: if needed, we restart apache - name: if needed, we restart apache
service: service:
name: httpd name: "{{ apache_service_name}}"
state: restarted state: restarted
when: result.changed when: result.changed
- name: generate certificates for domaine and subdomains - name: generate certificates for domaine and subdomains
vars: vars:
subdomains: "-d {{ apache_server_alias | join( ' -d ' ) }}" subdomains: "-d {{ apache_server_alias | join( ' -d ' ) }}"
command: certbot certonly --agree-tos --non-interactive -m {{ apache_ssl_root_email }} --webroot --webroot-path {{ apache_document_root }} -d {{ apache_server_name }} --test-cert {{ subdomains }} command: certbot certonly --agree-tos --non-interactive -m {{ apache_ssl_root_email }} --webroot --webroot-path {{ apache_document_root }} -d {{ apache_server_name }} {{ subdomains }}
args: args:
creates: "{{ apache_ssl_chain }}" creates: "{{ apache_ssl_chain }}"
when: apache_server_alias is defined when: apache_server_alias is defined
- name: generate certificates - name: generate certificates
command: certbot certonly --agree-tos --non-interactive -m {{ apache_ssl_root_email }} --webroot --webroot-path {{ apache_document_root }} -d {{ apache_server_name }} --test-cert command: certbot certonly --agree-tos --non-interactive -m {{ apache_ssl_root_email }} --webroot --webroot-path {{ apache_document_root }} -d {{ apache_server_name }}
args: args:
creates: "{{ apache_ssl_chain }}" creates: "{{ apache_ssl_chain }}"
when: apache_server_alias is not defined when: apache_server_alias is not defined
@@ -41,7 +41,7 @@
- name: deploy ssl config file - name: deploy ssl config file
template: template:
src: ssl.conf src: ssl.conf
dest: /etc/httpd/conf.d dest: "{{ apache_config_dir }}"
notify: restart apache notify: restart apache
- name: create cronjob for renewal - name: create cronjob for renewal

View File

@@ -1,15 +1,18 @@
--- ---
# tasks file for apache_vhost # tasks file for apache_vhost
- include_vars: "{{ ansible_os_family}}.yml"
tags: always
- name: create dedicated user - name: create dedicated user
user: user:
name: "{{ apache_user }}" name: "{{ apache_user }}"
groups: groups:
- apache - "{{ apache_group }}"
home: "{{ apache_base_dir }}" home: "{{ apache_base_dir }}"
shell: /bin/bash shell: /bin/bash
when: apache_user_password is not defined and apache_user != 'apache' when: apache_user_password is not defined and apache_user != 'apache'
tags: apache_user
- name: create dedicated user - ssh - name: create dedicated user - ssh
user: user:
@@ -20,13 +23,14 @@
home: "{{ apache_base_dir }}" home: "{{ apache_base_dir }}"
shell: /bin/bash shell: /bin/bash
when: apache_user_password is defined when: apache_user_password is defined
tags: apache_user
- name: create directories - name: create directories
file: file:
path: "{{ item }}" path: "{{ item }}"
state: directory state: directory
owner: "{{ apache_user }}" owner: "{{ apache_user }}"
group: apache group: "{{ apache_group }}"
mode: 0750 mode: 0750
loop: loop:
- "{{ apache_base_dir }}" - "{{ apache_base_dir }}"
@@ -35,10 +39,25 @@
- "{{ apache_base_dir }}/session" - "{{ apache_base_dir }}/session"
- "{{ apache_base_dir }}/wsdlcache" - "{{ apache_base_dir }}/wsdlcache"
- name: enable some modules
when: ansible_os_family == 'Debian'
tags: modules
community.general.apache2_module:
state: present
name: "{{ item }}"
loop: "{{ apache_modules_list }}"
- name: dns setup - name: dns setup
include_tasks: dns.yml include_tasks: dns.yml
when: apache_use_dns when: apache_use_dns
- name: remove default site
ansible.builtin.file:
path: /etc/apache2/sites-enabled/000-default.conf
state: absent
notify: restart apache
when: ansible_os_family| lower == 'debian'
- name: create certificate - name: create certificate
include_tasks: certbot.yml include_tasks: certbot.yml
when: apache_use_ssl when: apache_use_ssl
@@ -46,7 +65,7 @@
- name: vhost config file - name: vhost config file
template: template:
src: vhost.conf.jj src: vhost.conf.jj
dest: /etc/httpd/conf.d/{{ apache_server_name }}.conf dest: "{{ apache_config_dir }}/{{ apache_server_name }}.conf"
mode: 0644 mode: 0644
notify: restart apache notify: restart apache
@@ -60,3 +79,4 @@
import_tasks: goaccess.yml import_tasks: goaccess.yml
when: apache_use_stats when: apache_use_stats
tags: stats tags: stats

View File

@@ -1,6 +1,6 @@
[www_{{apache_server_name}}] [www_{{apache_server_name}}]
user = {{ apache_user }} user = {{ apache_user }}
group = apache group = {{ apache_group }}
listen = {{ apache_php_socket }} listen = {{ apache_php_socket }}
listen.owner = {{ apache_user }} listen.owner = {{ apache_user }}
listen.group = apache listen.group = apache

View File

@@ -1,4 +1,6 @@
{% if ansible_os_family | lower =='redhat' %}
Listen 443 https Listen 443 https
{% endif %}
SSLSessionCache shmcb:/run/httpd/sslcache(512000) SSLSessionCache shmcb:/run/httpd/sslcache(512000)
SSLSessionCacheTimeout 300 SSLSessionCacheTimeout 300
SSLCryptoDevice builtin SSLCryptoDevice builtin

View File

@@ -11,10 +11,12 @@
Options +indexes Options +indexes
</Directory> </Directory>
{%if apache_use_ssl %} {%if apache_use_ssl %}
<IfModule rewrite>
RewriteEngine on RewriteEngine on
RewriteCond %{HTTPS} off RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} "!^/\.well-known" RewriteCond %{REQUEST_URI} "!^/\.well-known"
RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L] RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L]
</IfModule>
{%endif %} {%endif %}
</VirtualHost> </VirtualHost>
@@ -26,6 +28,7 @@
ServerAlias {{ alias }} ServerAlias {{ alias }}
{%endfor%} {%endfor%}
{%endif%} {%endif%}
Protocols h2 http/1.1
DocumentRoot {{ apache_document_root }} DocumentRoot {{ apache_document_root }}
SSLEngine on SSLEngine on
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
@@ -42,7 +45,7 @@
</Directory> </Directory>
{%if apache_use_php %} {%if apache_use_php %}
<FilesMatch \.php$> <FilesMatch \.php$>
SetHandler "proxy:unix:{{ apache_php_socket }}|fcgi://localhost/" SetHandler "{{ php_listen_url }}"
</FilesMatch> </FilesMatch>
{% endif %} {% endif %}
</VirtualHost> </VirtualHost>

7
vars/Debian.yml Normal file
View File

@@ -0,0 +1,7 @@
#/home/tom/Documents/Opendoor/Technique/Ansible/roles/tconstans.apache/vars/Debian.yml
apache_packages:
- apache2
apache_ssl_packages: openssl
apache_group: www-data
apache_service_name: apache2
apache_config_dir: /etc/apache2/sites-enabled/

7
vars/RedHat.yml Normal file
View File

@@ -0,0 +1,7 @@
#/home/tom/Documents/Opendoor/Technique/Ansible/roles/tco.apache_vhost/vars/RedHat.yml
apache_config_dir: /etc/httpd/conf.d/
apache_packages:
- httpd
apache_service_name: httpd
apache_ssl_packages: mod_ssl
apache_group: apache