├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── Vagrantfile ├── ansible.cfg ├── defaults └── main.yml ├── handlers └── main.yml ├── meta └── main.yml ├── tasks └── main.yml ├── templates ├── traefik.service.j2 └── traefik.toml.j2 └── tests ├── inventory └── test.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: generic 3 | # Use the new container infrastructure 4 | sudo: required 5 | 6 | services: 7 | - docker 8 | 9 | env: 10 | - ANSIBLE_VERSION: 2.2 11 | - ANSIBLE_VERSION: 2.3 12 | - ANSIBLE_VERSION: 2.4 13 | - ANSIBLE_VERSION: 2.5 14 | - ANSIBLE_VERSION: 2.6 15 | - ANSIBLE_VERSION: 2.7 16 | 17 | install: 18 | # Pull container 19 | - sudo docker pull kitpages/docker-ansible:$ANSIBLE_VERSION 20 | 21 | # Check ansible version 22 | - sudo docker run -it --rm -v $(pwd):/ansible -w /ansible kitpages/docker-ansible:$ANSIBLE_VERSION ansible-playbook --version 23 | 24 | # Create ansible.cfg with correct roles_path 25 | - printf '[defaults]\nroles_path=../' >ansible.cfg 26 | 27 | script: 28 | # Basic role syntax check 29 | - sudo docker run -it --rm -v $(pwd):/ansible-traefik -w /ansible-traefik kitpages/docker-ansible:$ANSIBLE_VERSION ansible-playbook tests/test.yml -i tests/inventory --syntax-check 30 | 31 | notifications: 32 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ 33 | email: false 34 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at contact@kibatic.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Kibatic 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ❗❗❗ **This role is not maintained anymore** ❗❗❗ 2 | 3 | [archived] kibatic.traefik 4 | ========= 5 | 6 | ❗❗❗ **This role is not maintained anymore** ❗❗❗ 7 | 8 | Ansible role to deploy traefik binary and systemd unit. 9 | 10 | [![Build Status](https://travis-ci.org/kibatic/ansible-traefik.svg?branch=master)](https://travis-ci.org/kibatic/ansible-traefik) 11 | 12 | Træfɪk is a modern HTTP reverse proxy and load balancer made to deploy microservices with ease. It supports several backends (Docker, Swarm, Kubernetes, Marathon, Mesos, Consul, Etcd, Zookeeper, BoltDB, Rest API, file…) to manage its configuration automatically and dynamically. 13 | 14 | Installation 15 | -------------- 16 | 17 | `$ ansible-galaxy install kibatic.traefik` 18 | 19 | Role Variables 20 | -------------- 21 | 22 | ```yml 23 | traefik_install_dir: /usr/bin 24 | traefik_binary_url: https://github.com/containous/traefik/releases/download/v1.7.5/traefik_linux-amd64 25 | traefik_bin_path: "{{ traefik_install_dir }}/traefik" 26 | traefik_config_file: /etc/traefik.toml 27 | traefik_template: traefik.toml 28 | traefik_systemd_unit_template: traefik.service 29 | traefik_systemd_unit_dest: /etc/systemd/system/traefik.service 30 | ``` 31 | 32 | 33 | Configuration 34 | ---------------- 35 | 36 | Create a custom config file `templates/traefik.toml.j2`. 37 | Override template variable (e.g. in `group_vars/all.yml` ) 38 | 39 | ```yml 40 | traefik_template: templates/traefik.toml 41 | ``` 42 | 43 | Add role to your playbook. 44 | 45 | ```yml 46 | - hosts: servers 47 | roles: 48 | - { role: kibatic.traefik, tags: traefik } 49 | ``` 50 | 51 | Update Traefik 52 | -------------- 53 | 54 | You have to change `traefik_binary_url` or update this role. Then run your playbook 55 | with following **extra vars** : 56 | 57 | ```bash 58 | $ ansible-playbook playbook.yml -t traefik --extra-vars "traefik_update=yes" 59 | ``` 60 | 61 | Use same command if you want to downgrade. 62 | 63 | License 64 | ------- 65 | 66 | MIT 67 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # Vagrantfile API/syntax version. 2 | VAGRANTFILE_API_VERSION = "2" 3 | 4 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 5 | # Every Vagrant virtual environment requires a box to build off of. 6 | config.vm.box = "debian/jessie64" 7 | config.vm.hostname = "vagrant" 8 | config.vm.network "private_network", ip: "192.168.50.4" 9 | config.vm.provider :virtualbox do |virtualbox| 10 | virtualbox.name = "ansible-traefik" 11 | end 12 | config.vm.provision "ansible" do |ansible| 13 | ansible.sudo = true 14 | ansible.playbook = "tests/test.yml" 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | roles_path=../ -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file for kibatic.traefik 3 | traefik_install_dir: /usr/bin 4 | traefik_binary_url: https://github.com/containous/traefik/releases/download/v1.7.20/traefik_linux-amd64 5 | traefik_bin_path: "{{ traefik_install_dir }}/traefik" 6 | traefik_config_file: /etc/traefik.toml 7 | traefik_template: traefik.toml 8 | traefik_systemd_unit_template: traefik.service 9 | traefik_systemd_unit_dest: /etc/systemd/system/traefik.service 10 | traefik_update: no 11 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for kibatic.traefik 3 | - name: Restart traefik 4 | systemd: 5 | name: traefik 6 | state: restarted 7 | enabled: yes 8 | daemon_reload: yes 9 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Elie Charra 4 | description: Ansible role to deploy traefik binary and systemd unit 5 | company: Kibatic 6 | license: MIT 7 | min_ansible_version: 2.2 8 | platforms: 9 | - name: Ubuntu 10 | versions: 11 | - trusty 12 | - xenial 13 | - name: Debian 14 | versions: 15 | - jessie 16 | - name: EL 17 | versions: 18 | - 7 19 | galaxy_tags: 20 | - docker 21 | - reverseproxy 22 | - loadbalancer 23 | dependencies: [] 24 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | # tasks file for kibatic.traefik 2 | --- 3 | - name: Create traefik systemd unit 4 | template: 5 | src: "{{ traefik_systemd_unit_template }}.j2" 6 | dest: "{{ traefik_systemd_unit_dest }}" 7 | owner: root 8 | group: root 9 | mode: 0644 10 | notify: 11 | - Restart traefik 12 | 13 | - name: Ensure install & config directory exists 14 | file: 15 | path: "{{ item }}" 16 | state: directory 17 | with_items: 18 | - "{{ traefik_install_dir }}" 19 | - "{{ traefik_config_file | dirname }}" 20 | 21 | - name: Copy traefik config file 22 | template: 23 | src: "{{ traefik_template }}.j2" 24 | dest: "{{ traefik_config_file }}" 25 | owner: root 26 | group: root 27 | mode: 0644 28 | notify: 29 | - Restart traefik 30 | 31 | - name: Ensure traefik service is stopped before traefik update 32 | service: 33 | name: traefik 34 | state: stopped 35 | enabled: yes 36 | when: traefik_update | bool == True 37 | 38 | - name: check if traefik bin exists 39 | stat: 40 | path: "{{ traefik_bin_path }}" 41 | register: traefik_bin 42 | 43 | - name: Download Traefik binary 44 | unarchive: 45 | src: "{{ item.url }}" 46 | dest: "{{ item.dest }}" 47 | owner: root 48 | group: root 49 | mode: 0755 50 | remote_src: yes 51 | keep_newer: yes 52 | force: "{{ traefik_update | bool }}" 53 | with_items: 54 | - url: "{{ traefik_binary_url }}" 55 | dest: "{{ traefik_install_dir }}" 56 | when: traefik_bin.stat.exists == False 57 | 58 | - name: Ensure traefik service is enabled and running 59 | systemd: 60 | name: traefik 61 | state: started 62 | enabled: yes 63 | daemon_reload: yes 64 | -------------------------------------------------------------------------------- /templates/traefik.service.j2: -------------------------------------------------------------------------------- 1 | # This unit file is retrieved from traefik github repository 2 | # @see https://raw.githubusercontent.com/containous/traefik/master/contrib/systemd/traefik.service 3 | [Unit] 4 | Description=Traefik 5 | 6 | [Service] 7 | Type=notify 8 | ExecStart={{ traefik_bin_path }} --configFile={{ traefik_config_file }} 9 | Restart=on-failure 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /templates/traefik.toml.j2: -------------------------------------------------------------------------------- 1 | {# 2 | Check traefik sample for full config options 3 | https://raw.githubusercontent.com/containous/traefik/master/traefik.sample.toml 4 | #} 5 | logLevel = "INFO" 6 | 7 | [docker] 8 | endpoint = "unix:///var/run/docker.sock" 9 | domain = "localhost" 10 | watch = true 11 | -------------------------------------------------------------------------------- /tests/inventory: -------------------------------------------------------------------------------- 1 | localhost 2 | -------------------------------------------------------------------------------- /tests/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | roles: 4 | - ansible-traefik 5 | --------------------------------------------------------------------------------