made it work with teleport ansible script

This commit is contained in:
Expand 2023-09-24 14:18:33 +10:00
parent 5cdb1e5b7d
commit 2d8ba3e876
4 changed files with 25 additions and 13 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
Caddyfile
Caddyfile
Caddyfile.old

View file

@ -5,15 +5,21 @@
dest: /usr/bin/caddy
mode: '0751'
- name: create caddyfile
- name: save a copy of old file
ansible.builtin.fetch:
src: "{{ CADDYFILE_DEST }}"
dest: './caddyfile/Caddyfile.old'
when: SAVE_OLD
- name: create caddyfile if it does not exist
ansible.builtin.blockinfile:
block: |
localhost {
respond "200"
}
####
path: "{{ CADDYFILE_LOC }}"
path: "{{ CADDYFILE_DEST }}"
create: true
marker: "### {mark} Caddy configure setup stuffs ###"
- name: create Caddy systemd file
ansible.builtin.copy:
@ -28,8 +34,8 @@
Type=notify
User=root
Group=root
ExecStart=/usr/bin/caddy run --environ --config {{ CADDYFILE_LOC }}
ExecReload=/usr/bin/caddy reload --config {{ CADDYFILE_LOC }} --force
ExecStart=/usr/bin/caddy run --environ --config {{ CADDYFILE_DEST }}
ExecReload=/usr/bin/caddy reload --config {{ CADDYFILE_DEST }} --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
@ -49,5 +55,4 @@
daemon_reload: true
- name: install caddy trust
ansible.builtin.shell: "caddy trust"
ansible.builtin.shell: "caddy trust"

View file

@ -15,9 +15,9 @@
- name: copy existing Caddyfile to make sure there is a backup
ansible.builtin.copy:
src: "{{ CADDYFILE_LOC }}"
src: "{{ CADDYFILE_DEST }}"
remote_src: true
dest: "{{ CADDYFILE_LOC }}.bak"
dest: "{{ CADDYFILE_DEST }}.bak"
owner: root
group: root
mode: '0644'
@ -25,8 +25,9 @@
- name: Insert/Update configuration using a local file and validate it
ansible.builtin.blockinfile:
block: "{{ lookup('ansible.builtin.file', './caddyfile/Caddyfile') }}"
path: "{{ CADDYFILE_LOC }}"
insertafter: "####"
path: "{{ CADDYFILE_DEST }}"
insertafter: "### Caddy configure setup stuffs ###"
marker: "### {mark} user configured section ###"
- name: restart Caddy
ansible.builtin.systemd_service:

View file

@ -2,4 +2,9 @@
#if you want to install/upgrade caddy on the host above please set INSTALL_CADDY to true.
INSTALL_CADDY: true
#Put the location of your caddyfile should you need to manually edit it and want it in an easier place to find.
CADDYFILE_LOC: /etc/caddy/Caddyfile
CADDYFILE_DEST: /etc/caddy/Caddyfile
# if you already set up caddy before and need to save you caddy file to copy over to your new one set this to true.
# but it will likely just add the new stuff below your old configuration and keep everything working
# if you do want to delete you old caddy file and use caddyconfigure for everything change this to true, copy the contents from ../caddyfile/Caddyfile.old to ../caddyfile/Caddyfile,
# delete the Caddy file from the server and run the script again
SAVE_OLD: false