All Projects → decayofmind → ansible-bluegreen-docker

decayofmind / ansible-bluegreen-docker

Licence: MIT license
Ansible role, showing a concept of blue-green deployments with Docker containers

Programming Languages

Jinja
831 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to ansible-bluegreen-docker

ansible-aide
An Ansible role to install, configure, and schedule AIDE.
Stars: ✭ 14 (-39.13%)
Mutual labels:  ansible-role
Windows-2012-Member-Server-STIG
Ansible role for the Windows 2012 Member Server STIG
Stars: ✭ 12 (-47.83%)
Mutual labels:  ansible-role
tomcat role
Ansible role to install Apache Tomcat Java Servlet Container
Stars: ✭ 13 (-43.48%)
Mutual labels:  ansible-role
ansible-playbook-volumio-bluetooth
Pair your phone and stream audio to a Raspberry Pi running Volumio
Stars: ✭ 13 (-43.48%)
Mutual labels:  ansible-role
ansible-role-win-ec2
Ansible role to create and destroy Windows instances on EC2
Stars: ✭ 13 (-43.48%)
Mutual labels:  ansible-role
ansible-role-admin-users
Ansible role to manage admin users, authorized keys and sudo access.
Stars: ✭ 18 (-21.74%)
Mutual labels:  ansible-role
ansible-role-asdf
No description or website provided.
Stars: ✭ 45 (+95.65%)
Mutual labels:  ansible-role
ansible-mdadm
No description or website provided.
Stars: ✭ 48 (+108.7%)
Mutual labels:  ansible-role
ansible-role-mysql
Ansible Role - MySQL and MariaDB
Stars: ✭ 28 (+21.74%)
Mutual labels:  ansible-role
ansible-role-pacemaker
Ansible role to deploy Pacemaker HA clusters
Stars: ✭ 19 (-17.39%)
Mutual labels:  ansible-role
ansible-role-yarn
Ansible Role - YARN Package Manager for Ubuntu/RHEL/CentOS https://galaxy.ansible.com/ocha/yarn/
Stars: ✭ 27 (+17.39%)
Mutual labels:  ansible-role
ansible-role-nginx-config
Ansible role for configuring NGINX
Stars: ✭ 104 (+352.17%)
Mutual labels:  ansible-role
ansible-role-do-agent
Cross-distro installation of the DigitalOcean monitoring agent
Stars: ✭ 22 (-4.35%)
Mutual labels:  ansible-role
ansible-palybooks
Ansible Palybooks Written and Published by www.server-computer.com. NO WARRANTY for any damages and loss of data.
Stars: ✭ 24 (+4.35%)
Mutual labels:  ansible-role
ansible-haproxy
Installs and configures HAProxy
Stars: ✭ 19 (-17.39%)
Mutual labels:  ansible-role
ansible-concourse
An ansible role to manage Concourse CI
Stars: ✭ 22 (-4.35%)
Mutual labels:  ansible-role
ansible role proxmox
Ansible role to provision containers in Proxmox VE virtualization
Stars: ✭ 42 (+82.61%)
Mutual labels:  ansible-role
ansible-drone
Ansible role to configure drone (server and agent)
Stars: ✭ 16 (-30.43%)
Mutual labels:  ansible-role
cis ubuntu 2004
💻 Ansible Role for applying CIS Benchmark for Ubuntu Linux 20.04 LTS (hardening).
Stars: ✭ 30 (+30.43%)
Mutual labels:  ansible-role
ansible-role-etcd
Ansible role for installing etcd cluster
Stars: ✭ 38 (+65.22%)
Mutual labels:  ansible-role

Ansible Role: ansible-bluegreen-docker

Build Status

Simple Ansible role showing the concept of downtimeless deployments with Docker containers, but without orchestrator (Swarm, Kubernetes, etc.)

Disclaimer

Yes, I know about Kubernetes/Nomad/Swarm and other better methods to deploy an application in Docker containers. But there are cases, where the usage of orchestrator is bringing excessive complexity and is ""heavier" than an actual application workload.

If your infrastructure has one or two hosts and you need to deploy containerized web applications to them effectively, this role might be helpful.

The original pattern of blue-green deployments describes two copies of entire infrastructure with a router, switching traffic from old copy to a new one after a successful deployment.

This pattern can not be applied in this role to the full extent. However, during the run, the role will create a set of new containers alongside the old ones still running. The traffic will be switched to new containers (by modifying Nginx config) only after a successful healthcheck. So as you can see, the approach is quite similar to the original blue-green idea.

The deployment itself is done by docker_container Ansible module. Please refer to its documentation for more details.

Role Variables

Variable Description Default
app_name Application name. Also used for container naming. trainingwheels
app_image Name of the Docker image to pull. decayofmind/trainingwheels
app_port Internal TCP port where app is listening for connections. 5000
app_version Docker image tag. latest
app_instances_count Number of containers to be run. 2
app_command Command to be executed in a container ""
app_etc_hosts Custom hostname to IP mappings for /etc/hosts in container. {}
app_env Environment variables passed to a container's shell. {}
app_volumes Volumes mounted into container. []
app_log_driver Driver for capturing logs in containers. none
app_log_options Options for log driver. {}
app_port_prefix Prefix for ports, opened for containers on host if app_bluegreen_enabled is disabled. 401
app_bluegreen_enabled Enables downtimeless deployment. yes
app_bluegreen_default_color Tag for the first deployment (better to leave as is). green
app_bluegreen_tags.blue Hash with defaults for blue deployments (better to leave as is). {"name":"blue", "port_prefix": 402}
app_bluegreen_tags.green Hash with defaults for green deployments (better to leave as is). {"name":"green", "port_prefix": 407}
app_nginx_enabled Enables generation of Nginx config for balancing between containers. yes
app_nginx_hostnames Hostanames, which Nginx will accept. ["localhost"]
app_nginx_upstream_name Upstream name for Nginx configuration (better to leave as is). {{ app_name }}
app_nginx_port Port where Nginx is listening to incoming external requests. 80
app_nginx_ip_hash Enable ip-hash load-balancing algorithm for nginx. no
app_nginx_crossbalance_enabled Application containers of other hosts will be added to Nginx upstream if enabled. yes
app_nginx_crossbalance_hosts List of hosts to add to Nginx upstream (better to leave as is). {{ ansible_play_hosts }}
app_nginx_conf_backup_retention Count of Nginx configuration backup to keep 3
app_old_containers_treatment_enabled Enable to stop or remove containers left from the previous deployment. yes
app_old_containers_treatment_type What to do with containers of previous deployment (color). May be absent or stopped. absent
app_healthcheck_enabled Perform a healthcheck on newly deployed containers. yes
app_healthcheck_path Healthcheck path. /
app_cleanup_dead_containers Enables deletion of any dead containers left. yes

Temporary Variables

Following variables will appear in runtime:

Variable Description
_app_first_run Is True if role is run for the first time (local facts are checked for it).
_app_prev_color Tag of the previous deployment (fetched from local facts of app_default_color).
_app_prev_count Containers count of the previous deployment (fetched from local facts).
_app_prev_version Previous version of the deployed application (fetched from local facts).
_app_next_color Tag of the ongoing deployment. The opposite of _app_prev_color.
_app_deployemnt Returned values from docker_container module.
_app_ports Exposed ports of newly deployed containers (taken from _app_deployment).
_app_dead_containers Hashes of containers with dead status if found.
_app_healthcheck_result Result of ongoing healthchecks.
_app_nginx_conf_test Result of Nginx config check.

Requirements

  • docker-engine (not in meta)
  • nginx (not in meta)

Additionally for my test application (decayofmind/trainingwheels) you will need Redis.

Nginx Balancing

  1. Ansible gets a list of all published ports in containers.
  2. Ansible prepares an Nginx config with all published container's ports of all(!) app hosts.

Desired Architecture

architecture diagram

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].