# salt.modules.swarm

## Docker Swarm Module using Docker's Python SDK

codeauthor:

  Tyler Jones <jonestyler806@gmail.com>

Added in version 2018.3.0.

The Docker Swarm Module is used to manage and create Docker Swarms.

### Dependencies

- Docker installed on the host

- Docker python sdk >= 2.5.1

### Docker Python SDK

    pip install -U docker

More information: https://docker-py.readthedocs.io/en/stable/

salt.modules.swarm.joinswarm(remote_addr=<class 'int'>, listen_addr=<class 'int'>, token=<class 'str'>)

  Join a Swarm Worker to the cluster

  remote_addr

    The manager node you want to connect to for the swarm

  listen_addr

    Listen address used for inter-manager communication if the node gets promoted to manager, as well as determining the networking interface used for the VXLAN Tunnel Endpoint (VTEP)

  token

    Either the manager join token or the worker join token. You can get the worker or manager token via `salt '*' swarm.swarm_tokens`

  CLI Example:

      salt '*' swarm.joinswarm remote_addr=192.168.50.10 listen_addr='0.0.0.0'             token='SWMTKN-1-64tux2g0701r84ofq93zppcih0pe081akq45owe9ts61f30x4t-06trjugdu7x2z47j938s54il'

salt.modules.swarm.leave_swarm(force=<class 'bool'>)

  Force the minion to leave the swarm

  force

    Will force the minion/worker/manager to leave the swarm

  CLI Example:

      salt '*' swarm.leave_swarm force=False

salt.modules.swarm.node_ls(server=<class 'str'>)

  Displays Information about Swarm Nodes with passing in the server

  server

    The minion/server name

  CLI Example:

      salt '*' swarm.node_ls server=minion1

salt.modules.swarm.remove_node(node_id=<class 'str'>, force=<class 'bool'>)

  Remove a node from a swarm and the target needs to be a swarm manager

  node_id

    The node id from the return of swarm.node_ls

  force

    Forcefully remove the node/minion from the service

  CLI Example:

      salt '*' swarm.remove_node node_id=z4gjbe9rwmqahc2a91snvolm5 force=false

salt.modules.swarm.remove_service(service=<class 'str'>)

  Remove Swarm Service

  service

    The name of the service

  CLI Example:

      salt '*' swarm.remove_service service=Test_Service

salt.modules.swarm.service_create(image=<class 'str'>, name=<class 'str'>, command=<class 'str'>, hostname=<class 'str'>, replicas=<class 'int'>, target_port=<class 'int'>, published_port=<class 'int'>)

  Create Docker Swarm Service Create

  image

    The docker image

  name

    Is the service name

  command

    The docker command to run in the container at launch

  hostname

    The hostname of the containers

  replicas

    How many replicas you want running in the swarm

  target_port

    The target port on the container

  published_port

    port that's published on the host/os

  CLI Example:

      salt '*' swarm.service_create image=httpd name=Test_Service             command=None hostname=salthttpd replicas=6 target_port=80 published_port=80

salt.modules.swarm.swarm_init(advertise_addr=<class 'str'>, listen_addr=<class 'int'>, force_new_cluster=<class 'bool'>)

  Initialize Docker on Minion as a Swarm Manager

  advertise_addr

    The ip of the manager

  listen_addr

    Listen address used for inter-manager communication, as well as determining the networking interface used for the VXLAN Tunnel Endpoint (VTEP). This can either be an address/port combination in the form 192.168.1.1:4567, or an interface followed by a port number, like eth0:4567

  force_new_cluster

    Force a new cluster if True is passed

  CLI Example:

      salt '*' swarm.swarm_init advertise_addr='192.168.50.10' listen_addr='0.0.0.0' force_new_cluster=False

salt.modules.swarm.swarm_service_info(service_name=<class 'str'>)

  Swarm Service Information

  service_name

    The name of the service that you want information on about the service

  CLI Example:

      salt '*' swarm.swarm_service_info service_name=Test_Service

salt.modules.swarm.swarm_tokens()

  Get the Docker Swarm Manager or Worker join tokens

  CLI Example:

      salt '*' swarm.swarm_tokens

salt.modules.swarm.update_node(availability=<class 'str'>, node_name=<class 'str'>, role=<class 'str'>, node_id=<class 'str'>, version=<class 'int'>)

  Updates docker swarm nodes/needs to target a manager node/minion

  availability

    Drain or Active

  node_name

    minion/node

  role

    role of manager or worker

  node_id

    The Id and that can be obtained via swarm.node_ls

  version

    Is obtained by swarm.node_ls

  CLI Example:

      salt '*' swarm.update_node availability=drain node_name=minion2             role=worker node_id=3k9x7t8m4pel9c0nqr3iajnzp version=19