Role: httpd tasks

This commit is contained in:
Harvey Baxter 2025-07-07 10:12:50 +01:00
parent 2c9840d347
commit 217591d525
3 changed files with 52 additions and 46 deletions

View File

@ -0,0 +1,22 @@
---
- name: Create index.html
ansible.builtin.template:
src: httpd/index.html.j2
dest: "{{ httpd_site_root }}/index.html"
owner: www-data
group: www-data
mode: '0644'
- name: Create Apache virtual host config
ansible.builtin.template:
src: httpd/vhost.conf.j2
dest: "/etc/apache2/sites-available/{{ httpd_site_name }}.conf"
notify: Reload Apache
- name: Enable site
ansible.builtin.command: "a2ensite {{ httpd_site_name }}"
notify: Reload Apache
- name: Enable SSL module
ansible.builtin.command: a2enmod ssl
notify: Reload Apache

View File

@ -0,0 +1,22 @@
---
- name: Install Apache2
ansible.builtin.apt:
name: apache2
state: present
update_cache: true
- name: Install Certbot and Apache plugin
ansible.builtin.apt:
name:
- certbot
- python3-certbot-apache
state: present
- name: Ensure site root exists
ansible.builtin.file:
path: "{{ httpd_site_root }}"
state: directory
owner: www-data
group: www-data
mode: '0755'

View File

@ -1,55 +1,18 @@
---
- name: Install Apache2
ansible.builtin.apt:
name: apache2
state: present
update_cache: true
- name: Install Certbot and Apache plugin
ansible.builtin.apt:
name:
- certbot
- python3-certbot-apache
state: present
- name: Ensure site root exists
file:
path: "{{ httpd_site_root }}"
state: directory
owner: www-data
group: www-data
mode: '0755'
- name: Create index.html
template:
src: httpd/index.html.j2
dest: "{{ httpd_site_root }}/index.html"
owner: www-data
group: www-data
mode: '0644'
- name: Create Apache virtual host config
template:
src: httpd/vhost.conf.j2
dest: "/etc/apache2/sites-available/{{ httpd_site_name }}.conf"
notify: Reload Apache
- name: Enable site
command: "a2ensite {{ httpd_site_name }}"
notify: Reload Apache
- name: Enable SSL module
command: a2enmod ssl
notify: Reload Apache
- name: Apache2 Install
ansible.builtin.include_tasks: httpd_install.yml
- name: Apache2 Default Config
ansible.builtin.include_tasks: httpd_default_config.yml
- name: Ensure Apache is running and enabled
service:
ansible.builtin.service:
name: apache2
state: started
enabled: yes
enabled: true
- name: Obtain Let's Encrypt certificate using certbot
command: >
ansible.builtin.command: >
certbot --apache -n --agree-tos --redirect
-d {{ httpd_site_name }}
--email {{ admin_email }}
@ -57,6 +20,5 @@
creates: "/etc/letsencrypt/live/{{ httpd_site_name }}/fullchain.pem"
- name: PHP Application
when: httpd_php == true
when: httpd_php
ansible.builtin.include_tasks: php.yml