roles/caddy: added stub
roles/website: added
This commit is contained in:
parent
52de6b7b70
commit
00446943d7
@ -7,5 +7,6 @@
|
||||
- "sshd"
|
||||
- "ddclient"
|
||||
- "caddy"
|
||||
- "website"
|
||||
- "nameserver"
|
||||
- "mailserver"
|
||||
|
7
roles/caddy/defaults/main.yml
Normal file
7
roles/caddy/defaults/main.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
# these are defaults
|
||||
# override these in group/host vars
|
||||
|
||||
# web root directory
|
||||
website_path: /srv/http
|
17
roles/caddy/tasks/main.yml
Normal file
17
roles/caddy/tasks/main.yml
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
|
||||
- name: Install Caddy packages
|
||||
community.general.pacman:
|
||||
name: caddy
|
||||
state: present
|
||||
|
||||
- name: Configure Caddy
|
||||
template:
|
||||
src: Caddyfile.j2
|
||||
dest: /etc/caddy/Caddyfile
|
||||
|
||||
- name: Enable Caddy service
|
||||
service:
|
||||
name: caddy
|
||||
state: started
|
||||
enabled: yes
|
6
roles/caddy/templates/Caddyfile.j2
Normal file
6
roles/caddy/templates/Caddyfile.j2
Normal file
@ -0,0 +1,6 @@
|
||||
{% if website in servcices %}
|
||||
www.{{ domain }} {
|
||||
root * {{ website_path }}
|
||||
file_server
|
||||
}
|
||||
{% endif %}
|
13
roles/website/defaults/main.yml
Normal file
13
roles/website/defaults/main.yml
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
|
||||
# these are defaults
|
||||
# override these in group/host vars
|
||||
|
||||
# this user takes care of building the website
|
||||
# caddy will serve it
|
||||
website_username: ianitor
|
||||
|
||||
site_repo: https://git.dogeystamp.com/dogeystamp/wb5
|
||||
|
||||
# site gets deployed here
|
||||
website_path: /srv/http
|
59
roles/website/tasks/main.yml
Normal file
59
roles/website/tasks/main.yml
Normal file
@ -0,0 +1,59 @@
|
||||
- name: Create website deployment user
|
||||
user:
|
||||
name: "{{ website_username }}"
|
||||
|
||||
- name: Install required packages
|
||||
community.general.pacman:
|
||||
name:
|
||||
- git
|
||||
- make
|
||||
- moreutils
|
||||
- lowdown
|
||||
- rsync
|
||||
state: present
|
||||
|
||||
- name: Fetch site source
|
||||
git:
|
||||
dest: "/home/{{ website_username }}/website"
|
||||
repo: "{{ site_repo }}"
|
||||
register: site_source
|
||||
become_user: "{{ website_username }}"
|
||||
|
||||
- name: Make site directory in web root
|
||||
file:
|
||||
group: caddy
|
||||
owner: "{{ website_username }}"
|
||||
path: "{{ website_path }}"
|
||||
state: directory
|
||||
register: site_folder
|
||||
|
||||
- name: Deploy source to web root
|
||||
make:
|
||||
chdir: "/home/{{ website_username }}/website"
|
||||
target: deploy
|
||||
params:
|
||||
OUTPUT: "{{ website_path }}"
|
||||
when: site_source.changed or site_folder.changed
|
||||
become_user: "{{ website_username }}"
|
||||
|
||||
- name: Send deployment script
|
||||
template:
|
||||
src: deploy.sh.j2
|
||||
dest: "/home/{{ website_username }}/deploy.sh"
|
||||
mode: 0700
|
||||
owner: "{{ website_username }}"
|
||||
|
||||
- name: Tell cron to mail to root
|
||||
cron:
|
||||
user: "{{ website_username }}"
|
||||
name: MAILTO
|
||||
env: yes
|
||||
job: root
|
||||
|
||||
- name: Cronjob to deploy source
|
||||
cron:
|
||||
user: "{{ website_username }}"
|
||||
name: "Update and deploy website source"
|
||||
minute: 0
|
||||
hour: "*/1"
|
||||
job: "chronic /home/{{ website_username }}/deploy.sh"
|
7
roles/website/templates/deploy.sh.j2
Normal file
7
roles/website/templates/deploy.sh.j2
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
# website deployment script
|
||||
|
||||
set -e
|
||||
|
||||
git -C /home/{{ web_username }}/website pull
|
||||
make -C /home/{{ web_username }}/website build
|
Loading…
Reference in New Issue
Block a user