Skip to content

Commit

Permalink
Merge pull request #1 from arillso/improvements
Browse files Browse the repository at this point in the history
first improvements
  • Loading branch information
mleutenegger authored Jun 8, 2020
2 parents 8dc35a7 + 7629fc9 commit 63ffcbd
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 52 deletions.
31 changes: 22 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 32 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -21,6 +20,7 @@
<!-- /TOC -->

## 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.
Expand All @@ -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 |
Expand All @@ -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) |
Expand All @@ -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
Expand All @@ -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
Expand All @@ -141,22 +152,25 @@ 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.

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'
Expand Down
10 changes: 5 additions & 5 deletions tasks/0_config.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
---

- name: config | generate https entrypoint config
- name: "config : generate https entrypoint config"
set_fact:
traefik_int_conf_entryPoints: "{{
traefik_int_conf_entryPoints |
combine(traefik_int_conf_entryPoints_https)
}}"
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({})
Expand All @@ -31,7 +31,7 @@
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 }}"
Expand Down
26 changes: 13 additions & 13 deletions tasks/1_setup.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: setup | create traefik directory
- name: 'setup : create traefik directory'
become: true
file:
path: '{{ item }}'
Expand All @@ -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 }}'
Expand All @@ -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
13 changes: 6 additions & 7 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 63ffcbd

Please sign in to comment.