Skip to content

Commit

Permalink
traefik #1: it works
Browse files Browse the repository at this point in the history
  • Loading branch information
fititnt committed Apr 5, 2020
1 parent aa298d9 commit 901a1e0
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 14 deletions.
4 changes: 4 additions & 0 deletions ansible/inventories/etica.dev/hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ all:

# traefik_version: "2.2.0"
# traefik_arch: "linux_amd64"
## To force reinstall / update the traefik, please set this to yes
# traefik_force_reinstall: yes
# traefik_force_reinstall: yes
traefik_debug_devel: yes
6 changes: 5 additions & 1 deletion ansible/playbooks/roles/traefik/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
traefik_version: "2.2.0"
traefik_arch: "linux_amd64"
traefik_install_base: "/usr/local/bin/"
traefik_force_reinstall: yes

# To force reinstall / update the traefik, please set this to yes
traefik_force_reinstall: no

traefik_debug_devel: no

# traefik_download_url: "https://github.com/containous/traefik/releases/download/v2.2.0/traefik_v2.2.0_linux_amd64.tar.gz"
traefik_download_url: "https://github.com/containous/traefik/releases/download/v{{ traefik_version }}/traefik_v{{ traefik_version }}_{{ traefik_arch }}.tar.gz"
8 changes: 7 additions & 1 deletion ansible/playbooks/roles/traefik/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
---
# handlers file for traefik

- name: "restart service"
- name: "restart traefik"
systemd:
name: "traefik.service"
state: restarted
daemon_reload: yes

# Dont support reload? We will use "reload traefik" as an alias to restart (but not daemon restart)
- name: "reload traefik"
systemd:
name: "traefik.service"
state: restarted
18 changes: 11 additions & 7 deletions ansible/playbooks/roles/traefik/tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

# TODO: implement traefik.toml template (fititnt, 2020-04-05 11:08 BRT)

# - name: "Create systemd service"
# template:
# src: "traefik.toml.j2"
# dest: "/etc/systemd/system/traefik.service"
# mode: 0664
# notify:
# - restart service
- name: "Deploy traefik.toml"
template:
src: "traefik.toml.j2"
dest: "/etc/traefik/traefik.toml"
mode: 0664
block_start_string: "[[[%"
block_end_string: "%]]]"
variable_start_string: "[[["
variable_end_string: "]]]"
notify:
- reload traefik
9 changes: 8 additions & 1 deletion ansible/playbooks/roles/traefik/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
suffix: traefik_temp_dir
register: traefik_temp_dir

- name: "Create /etc/traefik/ it does not exist"
file:
path: "/etc/traefik/"
state: directory
mode: '0755'
become: yes

- name: "Download {{ traefik_download_url }}"
unarchive:
src: "{{ traefik_download_url }}"
Expand All @@ -27,4 +34,4 @@
dest: "/etc/systemd/system/traefik.service"
mode: 0664
notify:
- restart service
- "restart traefik"
8 changes: 5 additions & 3 deletions ansible/playbooks/roles/traefik/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# register: out
# - debug: var=out.stdout_lines

- name: "Check if {{ traefik_install_base }}/traefik exists"
- name: "Check if {{ traefik_install_base }}traefik exists"
stat:
path: "{{ traefik_install_base }}traefik"
register: stat_result
Expand All @@ -26,5 +26,7 @@
when:
- "(not stat_result.stat.exists) or (traefik_force_reinstall|bool)"

# - name: "configure.yml"
# include: configure.yml
- name: "configure.yml"
include: configure.yml

# TODO: create dedicated user traefik (fititnt, 2020-04-05 11:28 BRT)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Documentation=https://docs.traefik.io

# configure service behavior
Type=notify
ExecStart=/usr/bin/traefik --configFile=/etc/traefik/traefik.toml
ExecStart=/usr/local/bin/traefik --configFile=/etc/traefik/traefik.toml
Restart=always
WatchdogSec=1s

Expand Down
19 changes: 19 additions & 0 deletions ansible/playbooks/roles/traefik/templates/traefik.toml.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# {{ ansible_managed }}
#jinja2:variable_start_string:'[%' , variable_end_string:'%]'
################################################################
#
# Configuration sample for Traefik v2.
Expand Down Expand Up @@ -101,13 +103,15 @@
# Default: true
#
# insecure = false
# insecure = true

# Enabled Dashboard
#
# Optional
# Default: true
#
# dashboard = false
dashboard = true

################################################################
# Ping configuration
Expand Down Expand Up @@ -150,3 +154,18 @@
# Default: true
#
# exposedByDefault = false


[[[% if (traefik_debug_devel|bool) %]]]
# Dynamic Configuration
[http.routers.my-api]
rule = "Host(`traefik.hxl.etica.dev`)"
service = "api@internal"
middlewares = ["auth"]

[http.middlewares.auth.basicAuth]
users = [
"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
"test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
]
[[[% endif %]]]

0 comments on commit 901a1e0

Please sign in to comment.