2022-01-01 19:24:52 +01:00
|
|
|
---
|
2022-04-14 21:41:04 +02:00
|
|
|
- name: "Install nginx via apt"
|
2022-01-01 19:24:52 +01:00
|
|
|
apt:
|
|
|
|
update_cache: yes
|
|
|
|
state: present
|
|
|
|
name:
|
2022-04-14 21:41:04 +02:00
|
|
|
- nginx
|
|
|
|
- python3-certbot
|
|
|
|
- python3-certbot-nginx
|
2022-01-01 19:24:52 +01:00
|
|
|
|
2022-04-14 22:07:02 +02:00
|
|
|
- name: Allow http port via ufw
|
|
|
|
community.general.ufw:
|
|
|
|
rule: allow
|
|
|
|
port: http
|
|
|
|
|
|
|
|
- name: Allow https port via ufw
|
|
|
|
community.general.ufw:
|
|
|
|
rule: allow
|
|
|
|
port: https
|
|
|
|
|
2022-04-14 22:55:36 +02:00
|
|
|
- name: Copy default nginx config
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: nginx.conf
|
|
|
|
dest: /etc/nginx/nginx.conf
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
|
|
|
|
2022-04-14 21:41:04 +02:00
|
|
|
- name: Enable and restart nginx daemon
|
2022-01-01 19:24:52 +01:00
|
|
|
service:
|
2022-04-14 21:41:04 +02:00
|
|
|
name: nginx
|
2022-01-01 19:24:52 +01:00
|
|
|
state: restarted
|
|
|
|
enabled: yes
|
2022-02-05 20:00:55 +01:00
|
|
|
|
2022-04-14 23:28:13 +02:00
|
|
|
- name: Generate certificate for all proxied domains
|
|
|
|
command:
|
2022-04-14 23:34:50 +02:00
|
|
|
cmd: certbot certonly --non-interactive --agree-tos -m tormakristof@tormakristof.eu --nginx -d {{item.domain}}
|
2022-04-14 23:28:13 +02:00
|
|
|
with_items: "{{ proxy }}"
|
|
|
|
|
|
|
|
- name: Generate certificate for all static sites
|
|
|
|
command:
|
2022-04-14 23:34:50 +02:00
|
|
|
cmd: certbot certonly --non-interactive --agree-tos -m tormakristof@tormakristof.eu --nginx -d {{item.domain}}
|
2022-04-14 23:28:13 +02:00
|
|
|
with_items: "{{ static }}"
|
2022-04-14 21:41:04 +02:00
|
|
|
|
2022-05-04 19:20:27 +02:00
|
|
|
- name: Generate certificate for all redirect sites
|
2022-04-17 14:24:18 +02:00
|
|
|
command:
|
|
|
|
cmd: certbot certonly --non-interactive --agree-tos -m tormakristof@tormakristof.eu --nginx -d {{item.domain}}
|
|
|
|
with_items: "{{ redirect }}"
|
|
|
|
|
2022-04-14 21:41:04 +02:00
|
|
|
- name: "Generate certbot script"
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: certbot.sh
|
|
|
|
dest: /opt/certbot.sh
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0700'
|
|
|
|
|
|
|
|
- name: Copy certbot-script.service to target
|
|
|
|
copy:
|
|
|
|
src: certbot-script.service
|
|
|
|
dest: /usr/lib/systemd/system/certbot-script.service
|
|
|
|
mode: 644
|
|
|
|
owner: root
|
|
|
|
|
|
|
|
- name: Copy certbot.target to target
|
|
|
|
copy:
|
|
|
|
src: certbot.target
|
|
|
|
dest: /usr/lib/systemd/system/certbot.target
|
|
|
|
mode: 644
|
|
|
|
owner: root
|
|
|
|
|
|
|
|
- name: Copy certbot.timer to target
|
|
|
|
copy:
|
|
|
|
src: certbot.timer
|
|
|
|
dest: /usr/lib/systemd/system/certbot.timer
|
|
|
|
mode: 644
|
|
|
|
owner: root
|
|
|
|
|
|
|
|
- name: Enable certbot-script.service and reload systemd daemon
|
|
|
|
when: ansible_service_mgr == "systemd"
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
enabled: yes
|
|
|
|
daemon_reload: yes
|
|
|
|
name: certbot-script.service
|
|
|
|
|
|
|
|
- name: Enable certbot.target
|
|
|
|
when: ansible_service_mgr == "systemd"
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
enabled: yes
|
|
|
|
name: certbot.target
|
|
|
|
|
|
|
|
- name: Enable certbot.timer
|
|
|
|
when: ansible_service_mgr == "systemd"
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
enabled: yes
|
|
|
|
name: certbot.timer
|
|
|
|
|
|
|
|
- name: "Generate nginx configuration"
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: nginx.conf
|
|
|
|
dest: /etc/nginx/nginx.conf
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
|
|
|
|
2022-04-14 23:16:14 +02:00
|
|
|
- name: Validate nginx configuration
|
|
|
|
command:
|
|
|
|
cmd: nginx -t
|
|
|
|
|
|
|
|
- name: Reload nginx after configuration change
|
|
|
|
service:
|
|
|
|
name: nginx
|
|
|
|
state: reloaded
|
|
|
|
|
2022-04-14 23:43:03 +02:00
|
|
|
- name: "Remove any existing static file directories"
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ item.directory }}"
|
|
|
|
state: absent
|
|
|
|
with_items: "{{ static }}"
|
|
|
|
|
2022-04-14 23:09:44 +02:00
|
|
|
- name: "Checkout static websites from git"
|
|
|
|
ansible.builtin.git:
|
|
|
|
repo: "{{ item.repo }}"
|
|
|
|
dest: "{{ item.directory }}"
|
|
|
|
with_items: "{{ static }}"
|
|
|
|
|
|
|
|
- name: "Remove .git directory from static websites"
|
|
|
|
ansible.builtin.file:
|
2022-04-14 23:43:03 +02:00
|
|
|
path: "{{ item.directory }}/.git"
|
2022-04-14 23:09:44 +02:00
|
|
|
state: absent
|
2022-04-14 23:28:13 +02:00
|
|
|
with_items: "{{ static }}"
|
2022-04-16 19:55:29 +02:00
|
|
|
...
|