Bessonov.docker-swarm
Ansible Role to Set Up a Docker Swarm Cluster
This Role:
- Sets up a Docker Swarm cluster
- Manages both managers and worker nodes
This role uses a finite state machine approach, allowing it to adapt an existing cluster to the desired state. Please read the notes and test the process before running it!
For Docker installation, see Ansible Docker Role.
Requirements
You need Ansible version 2.3 and Docker installed.
Notes
If you need to change the manager nodes, at least one must remain unchanged during each run of the playbook. For example, to swap manager-1 with manager-2:
- Add manager-2 to the list of managers.
- Run the playbook.
- Remove manager-1 from the list of managers.
- Run the playbook again.
To demote or remove nodes using the playbook:
- Keep the nodes listed in the inventory (see the example below).
- Run the playbook.
- After that, you can remove any nodes that are no longer part of the cluster from the inventory.
Example Playbook
To install the role globally:
ansible-galaxy install Bessonov.docker-swarm
Or install it locally:
ansible-galaxy install --roles-path roles Bessonov.docker-swarm
Inventory (you can name the groups however you like; removed-nodes
is optional for new clusters):
[managers]
node-1
node-2
node-3
[workers]
node-1
node-3
node-4
[removed-nodes]
node-5
node-6
Playbook:
# Collect information about nodes that will be removed or demoted
- hosts: removed-nodes:workers
tasks: []
# Make sure Docker is installed first
# You can use any role for Docker installation
- hosts: managers:workers
roles:
- role: Bessonov.docker
- hosts: managers
# Docker CLI can't be accessed by multiple nodes at the same time
serial: 1
roles:
- role: Bessonov.docker-swarm
swarm_worker_hosts: workers
# Optional: Change default settings, see `defaults/main.yml`
swarm_cluster_bootstrap_parameters:
--advertise-addr: enp0s8
License
The MIT License (MIT)
Copyright (c) 2017, Anton Bessonov
You can use this software for free. You can use, copy, modify, and share it as long as you include the copyright notice and this permission notice with it.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY. The authors are not responsible for any claims or damages that may occur because of using this software.