Updated bitwarden to work with caddy
This commit is contained in:
1 parent
3ff953acdb
commit
e429ce661e
8 files changed
+62
-47
No files matched your search
@@ -2,11 +2,12 @@
|
|||||||
# Bitwarden Playbook
|
# Bitwarden Playbook
|
||||||
#################################################
|
#################################################
|
||||||
---
|
---
|
||||||
- hosts: gondor
|
- hosts: monoco
|
||||||
become: true
|
become: true
|
||||||
vars_files:
|
vars_files:
|
||||||
- vars/default.yml
|
- vars/default.yml
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
|
- network
|
||||||
- bitwarden
|
- bitwarden
|
||||||
- nginx
|
- caddy
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
# Tasks for Bitwarden role
|
# Tasks for Bitwarden role
|
||||||
- name: Pull Bitwarden Vault Warden image
|
- name: Pull Bitwarden Vault Warden image
|
||||||
docker_image:
|
docker_image:
|
||||||
name: "{{ container_image }}"
|
name: "{{ image_name }}"
|
||||||
source: pull
|
source: pull
|
||||||
force_source: yes
|
force_source: yes
|
||||||
|
|
||||||
@@ -14,16 +14,14 @@
|
|||||||
|
|
||||||
- name: Create bitwarden container
|
- name: Create bitwarden container
|
||||||
docker_container:
|
docker_container:
|
||||||
name: "{{ container_name }}"
|
name: "{{ docker_container }}"
|
||||||
image: "{{ container_image }}"
|
image: "{{ image_name }}"
|
||||||
state: started
|
state: started
|
||||||
restart_policy: "unless-stopped"
|
restart_policy: "unless-stopped"
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: "{{ db_url }}"
|
DATABASE_URL: "{{ db_url }}"
|
||||||
DOMAIN: "https://{{ http_host }}"
|
DOMAIN: "https://{{ host }}"
|
||||||
links:
|
|
||||||
- "postgres:db"
|
|
||||||
published_ports:
|
|
||||||
- 127.0.0.1:8080:80
|
|
||||||
volumes:
|
volumes:
|
||||||
- "/var/lib/{{ host_directory }}/data:/data/"
|
- "/var/lib/{{ host_directory }}/data:/data/"
|
||||||
|
networks:
|
||||||
|
- name: "{{ docker_network }}"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
# Handlers for Caddy role
|
||||||
|
- name: Reload Caddy configuration
|
||||||
|
ansible.builtin.command: "docker exec -w /etc/caddy {{ caddy_container }} caddy reload"
|
||||||
|
listen: "Reload Caddy"
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
- name: Read current Caddyfile
|
||||||
|
ansible.builtin.slurp:
|
||||||
|
path: "{{ caddyfile_path }}"
|
||||||
|
register: caddyfile_raw
|
||||||
|
|
||||||
|
- name: Decode Caddyfile content
|
||||||
|
set_fact:
|
||||||
|
caddyfile_content: "{{ caddyfile_raw['content'] | b64decode }}"
|
||||||
|
|
||||||
|
- name: Check if snippet already exists
|
||||||
|
set_fact:
|
||||||
|
snippet_present: "{{ snippet_block in caddyfile_content }}"
|
||||||
|
|
||||||
|
- name: Add snippet if missing
|
||||||
|
ansible.builtin.blockinfile:
|
||||||
|
path: "{{ caddyfile_path }}"
|
||||||
|
marker: "# {mark} Ansible managed Caddy snippet for {{ host }}"
|
||||||
|
block: "{{ snippet_block }}"
|
||||||
|
create: yes
|
||||||
|
when: not snippet_present
|
||||||
|
notify: "Reload Caddy"
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
- name: "Ensure {{ docker_container }} Docker network exists"
|
||||||
|
docker_network:
|
||||||
|
name: "{{ docker_network }}"
|
||||||
|
state: present
|
||||||
|
connected:
|
||||||
|
- "{{ caddy_container }}"
|
||||||
|
- "{{ postgres_container }}"
|
||||||
|
appends: yes
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
# Handlers for Nginx role
|
|
||||||
- name: Reload Nginx
|
|
||||||
service:
|
|
||||||
name: nginx
|
|
||||||
state: reloaded
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
# Tasks for Nginx role
|
|
||||||
- name: Check if Nginx conf file exists
|
|
||||||
stat:
|
|
||||||
path: "/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
register: status
|
|
||||||
|
|
||||||
- name: No need to reload Nginx
|
|
||||||
debug:
|
|
||||||
msg: "No need to reload Nginx as sites-available entries have already been created"
|
|
||||||
|
|
||||||
- name: Set Nginx conf file
|
|
||||||
when: status.stat.exists == false
|
|
||||||
template:
|
|
||||||
src: "files/nginx.conf.j2"
|
|
||||||
dest: "/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
|
|
||||||
- name: Enable new site
|
|
||||||
when: status.stat.exists == false
|
|
||||||
file:
|
|
||||||
src: "/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
|
|
||||||
state: link
|
|
||||||
notify: Reload Nginx
|
|
||||||
@@ -1,11 +1,21 @@
|
|||||||
---
|
---
|
||||||
http_host: "vault.tanshu.com"
|
host: vault.tanshu.com
|
||||||
http_conf: "vault.tanshu.com.conf"
|
|
||||||
|
|
||||||
container_name: bitwarden
|
docker_container: bitwarden
|
||||||
container_image: vaultwarden/server:latest
|
image_name: vaultwarden/server:latest
|
||||||
|
|
||||||
db_server: db
|
host_directory: bitwarden
|
||||||
db_url: postgresql://postgres:123456@{{ db_server }}:5432/bitwarden
|
|
||||||
|
docker_network: "{{ docker_container }}_net"
|
||||||
|
|
||||||
|
postgres_container: postgres
|
||||||
|
caddy_container: caddy
|
||||||
|
|
||||||
|
caddyfile_path: /var/lib/caddy/conf/Caddyfile
|
||||||
|
snippet_block: |
|
||||||
|
{{ host }} {
|
||||||
|
reverse_proxy {{ docker_container }}:80
|
||||||
|
}
|
||||||
|
|
||||||
|
db_url: postgresql://postgres:123456@{{ postgres_container }}:5432/bitwarden
|
||||||
|
|
||||||
host_directory: bitwarden
|
|
||||||
Reference in new issue
Block a user