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

1
.gitignore vendored
View file

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

View file

@ -5,15 +5,21 @@
dest: /usr/bin/caddy dest: /usr/bin/caddy
mode: '0751' 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: ansible.builtin.blockinfile:
block: | block: |
localhost { localhost {
respond "200" respond "200"
} }
#### path: "{{ CADDYFILE_DEST }}"
path: "{{ CADDYFILE_LOC }}"
create: true create: true
marker: "### {mark} Caddy configure setup stuffs ###"
- name: create Caddy systemd file - name: create Caddy systemd file
ansible.builtin.copy: ansible.builtin.copy:
@ -28,8 +34,8 @@
Type=notify Type=notify
User=root User=root
Group=root Group=root
ExecStart=/usr/bin/caddy run --environ --config {{ CADDYFILE_LOC }} ExecStart=/usr/bin/caddy run --environ --config {{ CADDYFILE_DEST }}
ExecReload=/usr/bin/caddy reload --config {{ CADDYFILE_LOC }} --force ExecReload=/usr/bin/caddy reload --config {{ CADDYFILE_DEST }} --force
TimeoutStopSec=5s TimeoutStopSec=5s
LimitNOFILE=1048576 LimitNOFILE=1048576
LimitNPROC=512 LimitNPROC=512
@ -50,4 +56,3 @@
- name: install caddy trust - 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 - name: copy existing Caddyfile to make sure there is a backup
ansible.builtin.copy: ansible.builtin.copy:
src: "{{ CADDYFILE_LOC }}" src: "{{ CADDYFILE_DEST }}"
remote_src: true remote_src: true
dest: "{{ CADDYFILE_LOC }}.bak" dest: "{{ CADDYFILE_DEST }}.bak"
owner: root owner: root
group: root group: root
mode: '0644' mode: '0644'
@ -25,8 +25,9 @@
- name: Insert/Update configuration using a local file and validate it - name: Insert/Update configuration using a local file and validate it
ansible.builtin.blockinfile: ansible.builtin.blockinfile:
block: "{{ lookup('ansible.builtin.file', './caddyfile/Caddyfile') }}" block: "{{ lookup('ansible.builtin.file', './caddyfile/Caddyfile') }}"
path: "{{ CADDYFILE_LOC }}" path: "{{ CADDYFILE_DEST }}"
insertafter: "####" insertafter: "### Caddy configure setup stuffs ###"
marker: "### {mark} user configured section ###"
- name: restart Caddy - name: restart Caddy
ansible.builtin.systemd_service: 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. #if you want to install/upgrade caddy on the host above please set INSTALL_CADDY to true.
INSTALL_CADDY: 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. #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