Ansible roles for deploying a docker swarm.
Documentation and more detailed examples are hosted on Github Pages.
Select the first member of the manager group and have them initiate a swarm.
- hosts: &swarm_initiator manager[0]
user: root
vars:
- domains: example.com
roles:
- joellefkowitz.swarmroles.swarm_initiator
Register the first member of the manager group as the swarm_initiator and pass the swarm tokens to the rest of the manager group. Provide a list of images to pull and a docker username if the images require a login for access. An access token can be issued under the environment variable name DOCKER_ACCESS_TOKEN.
- hosts: manager
user: root
vars:
- docker_username: joellefkowitz
- pull_images:
- joellefkowitz/example:0.1.0_prod
pre_tasks: ®ister_swarm_initiator
- name: Fetch the swarm initiator host
set_fact:
swarm_initiator: "{{groups['manager'][0]}}"
roles:
- role: joellefkowitz.swarmroles.swarm_manager
swarm_join_addr: "{{ hostvars[swarm_initiator]['swarm_join_addr'] }}"
swarm_manager_token: "{{ hostvars[swarm_initiator]['swarm_manager_token'] }}"
Perform the same registration for all members of the worker group.
- hosts: worker
user: root
pre_tasks: *register_swarm_initiator
roles:
- role: joellefkowitz.swarmroles.swarm_worker
swarm_join_addr: "{{ hostvars[swarm_initiator]['swarm_join_addr'] }}"
swarm_worker_token: "{{ hostvars[swarm_initiator]['swarm_worker_token'] }}"
Have a manager deploy the swarm. Copy over the compose file and any environment files required.
- hosts: *swarm_initiator
user: root
vars:
- stack_name: prod
- compose_file: docker-compose.yml
- env_files:
- prod.example.env
roles:
- joellefkowitz.swarmroles.stack_deployer
Installs python and setuptools
Installs the docker engine for Ubuntu
- base
Initializes a docker swarm
- docker
- swarm_join_addr
- swarm_manager_token
- swarm_worker_token
Joins a docker swarm as a manager and pulls a list of images.
- docker
- swarm_join_addr
- swarm_manager_token
- docker_username
- pull_images (List of strings)
- DOCKER_ACCESS_TOKEN
- Docker login will only be attempted when docker_username is defined
Joins a docker swarm as a worker
- docker
- swarm_join_addr
- swarm_worker_token
Deploys a stack to a docker swarm
- docker
- deploy_dir (Defaults to 'deploy')
- compose_file
- env_files (List of strings)
- stack_name
To install dependencies:
yarn install
pip install .[all]
To run tests:
thx test
To generate the documentation locally:
thx docs
To run linters:
thx lint
To run formatters:
thx format
Please read this repository's Code of Conduct which outlines our collaboration standards and the Changelog for details on breaking changes that have been made.
This repository adheres to semantic versioning standards. For more information on semantic versioning visit SemVer.
Bump2version is used to version and tag changes. For example:
bump2version patch
- Joel Lefkowitz - Initial work
Lots of love to the open source community!