From 2cf4adda02497fdd10d329f9031ccaac4d733f0d Mon Sep 17 00:00:00 2001 From: Simon Baerlocher Date: Wed, 3 Jun 2020 16:09:38 +0200 Subject: [PATCH 1/2] first improvements --- CHANGELOG.md | 31 +++++++++++++++++++--------- README.md | 50 +++++++++++++++++++++++++++++----------------- tasks/0_config.yml | 12 +++++------ tasks/1_setup.yml | 26 ++++++++++++------------ vars/main.yml | 13 ++++++------ 5 files changed, 79 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35c4b76..a5d1056 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,27 +3,40 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [human-readable changelog](https://keepachangelog.com/en/1.0.0/). - ## [Unreleased] +### Changed + +- Adaptation of the task names +- Syntax adapted to standard +- Conversion of the traefik ocnfig dir variable from `traefik_host_vol` to `traefik_dir` + ## [1.0.2] - 2020-05-31 + ### Fixed -* recursive variable definition -* traefik volumes + +- recursive variable definition +- traefik volumes ## [1.0.1] - 2020-05-30 + ### Added -* Compatibility for [sbaerlocher/ansible.traefik](https://github.com/sbaerlocher/ansible.traefik) + +- Compatibility for [sbaerlocher/ansible.traefik](https://github.com/sbaerlocher/ansible.traefik) + ### Changed -* no `set_fact` step for service generation anymore -* using `networks_cli_compatible` for service generation + +- no `set_fact` step for service generation anymore +- using `networks_cli_compatible` for service generation + ### Fixed -* Certresolver config key is left undefined if no resolver is defined + +- Certresolver config key is left undefined if no resolver is defined ## 1.0.0 -* initial release +- initial release -[Unreleased]: https://github.com/arillso/ansible.traefik/compare/1.0.2...HEAD +[unreleased]: https://github.com/arillso/ansible.traefik/compare/1.0.2...HEAD [1.0.2]: https://github.com/arillso/ansible.traefik/compare/1.0.1...1.0.2 [1.0.1]: https://github.com/arillso/ansible.traefik/compare/1.0.0...1.0.1 diff --git a/README.md b/README.md index 54cf6e6..673bb05 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Ansible Role: traefik - [![Build Status](https://img.shields.io/travis/arillso/ansible.traefik.svg?branch=master&style=popout-square)](https://travis-ci.org/arillso/ansible.traefik) [![Ansible Galaxy](https://img.shields.io/badge/ansible--galaxy-traefik-blue.svg?style=popout-square)](https://galaxy.ansible.com/arillso/traefik) [![Ansible Role](https://img.shields.io/ansible/role/d/48963.svg?style=popout-square)](https://galaxy.ansible.com/arillso/traefik) @@ -21,6 +20,7 @@ ## Description + [Traefik](https://docs.traefik.io/v2.0) is a reverse proxy written in Go. It can be used in multiple situations with many providers (Kubernetes, Swarm, ...). Version 2 is also capable of TCP routing. @@ -34,27 +34,31 @@ allows you, to use one server as a host for multiple dockerized applications. > Kubernetes or other systems and setup traefik there. ## Installation -``` + +```bash ansible-galaxy install arillso.traefik ``` ## Requirements -* Docker + +- Docker ## Role Variables + Traefik v2.0 onwards supports yaml configuration. This role uses this to generate the configuration directly from the given ansible variables. There are certain quick-setup variables, which allow you to setup a simple instance, but there is also the option to fully configure every key yourself. The quick-setup allows you to: -* Setup a lets-encrypt based certificate resolver -* Setup standard entrypoints -* Setup standard Docker provider + +- Setup a lets-encrypt based certificate resolver +- Setup standard entrypoints +- Setup standard Docker provider The quick-setup variables are prefixed with `traefik_qs_`. | Name | Default | Description | -|:--------------------------------- |:---------------------------- |:---------------------------------------------------------------- | +| :-------------------------------- | :--------------------------- | :--------------------------------------------------------------- | | `traefik_dir` | `/etc/traefik` | where to store traefik data | | `traefik_hostname` | `"{{ inventory_hostname }}"` | the hostname of this instance | | `traefik_network` | `traefik_proxy` | the name of the generated network | @@ -75,21 +79,22 @@ The quick-setup variables are prefixed with `traefik_qs_`. | `traefik_labels` | `{}` | labels to set on the traefik container. | The default names of the generated configs are: -* Entrypoints: - * `web_http` - * `web_https` -* Providers: - * `docker` -* Certificate Resolvers: - * `letsencrypt` +- Entrypoints: + - `http` + - `https` +- Providers: + - `docker` +- Certificate Resolvers: + - `letsencrypt` ### In-Depth Configuration + As stated before, this role also allows you to configure traefik in-depth by using the traefik yaml config. The following variables can be used: | Name | Default | Description | -|:--------------------------------------- |:--------- | ------------------------------------------------------------------------------ | +| :-------------------------------------- | :-------- | ------------------------------------------------------------------------------ | | `traefik_confkey_global` | undefined | [see Docs 📑](https://docs.traefik.io/reference/static-configuration/file/) | | `traefik_confkey_serversTransport` | undefined | [see Docs 📑](https://docs.traefik.io/reference/static-configuration/cli-ref/) | | `traefik_confkey_entryPoints` | undefined | [see Docs 📑](https://docs.traefik.io/routing/entrypoints/#entrypoints) | @@ -109,21 +114,26 @@ filter in non recursive mode. This allows you to add configuration options as you need them. If you want to overwrite the quick-setup items, use their key (as specified above). -## Compatibility with sbaerlocher/ansible.traefik +## Compatibility with sbaerlocher/ansible.traefik + This role is intended as a continuation of the [sbaerlocher/ansible.traefik](https://github.com/sbaerlocher/ansible.traefik) role for traefik v2. Most of the variables set for said role will continue to work in this role, except for three special cases, where you **must** recreate a custom configuration using the `_confkey_` variables. These are explained in the following sections. + ### Variables which need manual action + #### `traefik_configuration_file` + Using the `traefik_configuration_file` has no influence on your installation. The configuration of Traefik has changed with the introduction of v2 and is not backwards compatible. Use the [Traefik docs](https://docs.traefik.io/reference/static-configuration/file/) to recreate your custom configuration using the `_confkey_` variables. #### `traefik_api` + The way API is defined in Traefik v2 allows you, to use [several diffrent configurations](https://docs.traefik.io/operations/api/). For the sake of simplicity, we dropped the automatic generation of an api config, as it not @@ -132,6 +142,7 @@ simply mergeable with a custom config and could lead to unforseen side effects. To setup a simple, insecure api on container port `8080`, use the following config (**Note**: this example is insecure, please consider securing your api for use in production): + ```yaml traefik_confkey_api: insecure: true @@ -141,9 +152,11 @@ traefik_ports: - '443:443' - '8080:8080' ``` + This will automatically configure an [entrypoint on port `8080`](https://docs.traefik.io/operations/api/). #### `traefik_ping` + Similar to the api definition, the ping definition allows custom configuration over multiple diffrent configuration keys, making an automatically generated config unfeasable. @@ -151,12 +164,13 @@ config unfeasable. Follow the [Traefik config docs about ping](https://docs.traefik.io/operations/ping/) to find the configuration you want to apply. As an Example, take a look at this config, which will expose the ping endpoint on port `8082`: + ```yaml traefik_confkey_entryPoints: ping: - address: ":8082" + address: ':8082' traefik_confkey_ping: - entryPoint: "ping" + entryPoint: 'ping' traefik_ports: - '80:80' - '443:443' diff --git a/tasks/0_config.yml b/tasks/0_config.yml index 78a9f2d..c56232d 100644 --- a/tasks/0_config.yml +++ b/tasks/0_config.yml @@ -1,6 +1,6 @@ --- -- name: config | generate https entrypoint config +- name: "config : generate https entrypoint config" set_fact: traefik_int_conf_entryPoints: "{{ traefik_int_conf_entryPoints | @@ -8,30 +8,30 @@ }}" when: traefik_qs_https -- name: config | generate https redirect config +- name: "config : generate https redirect config" set_fact: traefik_int_conf_entryPoints: "{{ traefik_int_conf_entryPoints | combine(traefik_int_conf_entryPoints_https_redirect, recursive=True) }}" when: traefik_qs_https and traefik_qs_https_redirect -- name: config | generate neutral certresolver +- name: "config : generate neutral certresolver" set_fact: traefik_conf_certificatesResolvers: "{{ traefik_int_conf_certificatesResolvers_le }}" when: traefik_qs_https and traefik_qs_https_le -- name: config | generate neutral certresolver +- name: "config : generate neutral certresolver" set_fact: traefik_conf_certificatesResolvers: "{{ traefik_conf_certificatesResolvers | default({}) - | combine(traefik_confkey_certificatesResolvers) + | combine(.) }}" when: traefik_confkey_certificatesResolvers is defined -- name: config | generate static config +- name: "config : generate static config" set_fact: traefik_static_config: global: "{{ traefik_conf_global }}" diff --git a/tasks/1_setup.yml b/tasks/1_setup.yml index e8ecdf8..26df5ba 100644 --- a/tasks/1_setup.yml +++ b/tasks/1_setup.yml @@ -1,5 +1,5 @@ --- -- name: setup | create traefik directory +- name: 'setup : create traefik directory' become: true file: path: '{{ item }}' @@ -8,20 +8,20 @@ group: docker mode: 0550 with_items: - - "{{ traefik_host_vol }}" + - '{{ traefik_dir }}' -- name: setup | create traefik configuration +- name: 'setup : create traefik configuration' become: true copy: - dest: "{{ traefik_host_vol }}traefik.yml" + dest: '{{ traefik_dir }}/traefik.yml' owner: root group: docker mode: 0550 - content: "{{ traefik_static_config | to_nice_yaml }}" + content: '{{ traefik_static_config | to_nice_yaml }}' notify: - restart traefik container -- name: setup | create traefik network +- name: 'setup : create traefik network' become: true docker_network: name: '{{ traefik_network_name }}' @@ -30,17 +30,17 @@ gateway: '{{ traefik_network_ipam_gateway }}' iprange: '{{ traefik_network_ipam_iprange }}' -- name: setup | start traefik container +- name: 'setup : start traefik container' become: true docker_container: - name: "{{ traefik_container_name }}" - image: "{{ traefik_image }}" + name: '{{ traefik_container_name }}' + image: '{{ traefik_image }}' restart_policy: unless-stopped - published_ports: "{{ traefik_ports }}" - volumes: "{{ traefik_volumes + traefik_add_volumes }}" - labels: "{{ traefik_labels }}" + published_ports: '{{ traefik_ports }}' + volumes: '{{ traefik_volumes + traefik_add_volumes }}' + labels: '{{ traefik_labels }}' command: - - "--configFile={{ traefik_host_vol }}traefik.yml" + - '--configFile=/etc/traefik/traefik.yml' networks: - name: '{{ traefik_network_name }}' networks_cli_compatible: true diff --git a/vars/main.yml b/vars/main.yml index 3bc1ab6..d0d8f5d 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -3,19 +3,19 @@ traefik_int_conf_global: sendAnonymousUsage: "{{ traefik_qs_send_anonymous_usage }}" traefik_int_conf_entryPoints: - web_http: + http: address: :80 traefik_int_conf_entryPoints_https: - web_https: + https: address: :443 traefik_int_conf_entryPoints_https_redirect: - web_http: + http: http: redirections: entryPoint: - to: web_https + to: https scheme: https traefik_int_conf_providers: @@ -55,10 +55,9 @@ traefik_conf_log: "{{ # }}" -traefik_host_vol: /etc/traefik/ traefik_volumes: - /etc/localtime:/etc/localtime:ro - "/var/run/docker.sock:/var/run/docker.sock:ro" - - "{{ traefik_host_vol }}traefik.yml:/etc/traefik/traefik.yml" - - "{{ traefik_host_vol }}letsencrypt/:/letsencrypt/:rw" + - "{{ traefik_dir }}/traefik.yml:/etc/traefik/traefik.yml" + - "{{ traefik_dir }}/letsencrypt/:/letsencrypt/:rw" - traefik-data:/etc/traefik From 7629fc997e5bbf982ae2f02d631586761a2174b3 Mon Sep 17 00:00:00 2001 From: Simon Baerlocher Date: Mon, 8 Jun 2020 09:48:01 +0200 Subject: [PATCH 2/2] Variable fixed --- tasks/0_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/0_config.yml b/tasks/0_config.yml index c56232d..6b0c609 100644 --- a/tasks/0_config.yml +++ b/tasks/0_config.yml @@ -26,7 +26,7 @@ set_fact: traefik_conf_certificatesResolvers: "{{ traefik_conf_certificatesResolvers | default({}) - | combine(.) + | combine(traefik_confkey_certificatesResolvers) }}" when: traefik_confkey_certificatesResolvers is defined