2025-07-04 17:03:37 +01:00

63 lines
1.3 KiB
YAML

---
- 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: Ensure Apache is running and enabled
service:
name: apache2
state: started
enabled: yes
- name: Obtain Let's Encrypt certificate using certbot
command: >
certbot --apache -n --agree-tos --redirect
-d {{ httpd_site_name }}
--email {{ admin_email }}
args:
creates: "/etc/letsencrypt/live/{{ httpd_site_name }}/fullchain.pem"
- name: PHP Application
when: httpd_php == true
ansible.builtin.include_tasks: php.yml