3

I'm trying to deploy a Docker service into swarm but always ending up with running container on my localhost (the one I use as a docker swarm manager) and no service

Here's my setup:

I have 3 node Docker (v. 1.12.1) swarm that includes one host running as manager and two worker nodes all running on CentOS 7. On the manager node (localhost) I run Ansible (v. 2.1.1.0) playbook and the swarm is already configured and is running

Swarm: active
 NodeID: d9h5xa832ax7wzeq8q44fjld3
 Is Manager: true
 ClusterID: 9cztoin3gy2ntbwehsmrkjuxi
 Managers: 1
 Nodes: 3
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
 Node Address: 10.25.190.209

Starting with a playbook that has this code

- hosts: localhost
  name: Run JMeter test
  vars_files:
    - user.config.yml
  vars:
    execute_tpcds_test : "{{ run_tpcds_test }}"    
  roles:
    - { role: run_jmeter, when: execute_tpcds_test is defined and execute_tpcds_test ==1 }

Which calls this role:

- name: Deploy tpcds_tpg service to swarm
  docker_service:
    project_name: tpcds-tpg
    definition:
      version: '2'
      services:
        run_tests: 
          image: 'pbench/tpcds_tpg'
          volumes: 
            - /opt/pbench/run_output/
          command: ./run_jmeter.sh "{{jmeter_output_dir}}" 
  register: output
- debug: var=output

When I run ansible-playbook ./site.yml I end up with a running container. Doing docker ps -a displays

[pdo@sdl02133 tpcds-tpg]$ docker ps -a
CONTAINER ID        IMAGE              COMMAND                  CREATED             STATUS              PORTS               NAMES
fef245b41365        pbench/tpcds_tpg   "./run_jmeter.sh /opt"   21 seconds ago      Up 20 seconds                           tpcdstpg_run_tests_1

And doing docker service ls shows no services running so it looks like docker_service deploys my image as a local container and not as a service on the swarm

So my assumption was that if I have an active swarm on the machine that is a swarm manager and I use Ansible docker_service module, then it will automatically be aware of the swarm and deploy the service to it. Looks like my assumption is wrong and I cannot find any docs, blog posts, etc. that would hint me what to do and what I am missing. Ansible experts please help!

Bostone
  • 1,213
  • 2
  • 9
  • 8
  • 3
    I would expect a 7+ years user of StackExchange to know that [crossposting](https://stackoverflow.com/questions/39925167/using-ansible-docker-service-module-to-deploy-service-to-swarm) is discouraged. – techraf Oct 10 '16 at 15:33
  • @techraf you are right, dutifully noted and to my defence this is first time I'm doing this because I hate to admit but I'm desperate for answer. Unfortunately I placed the bounty on the Stackoverflow question that I hate to vaste. Would you suggest me to delete this question? – Bostone Oct 10 '16 at 16:33

1 Answers1

0

Found the answer finally. Basically my assumption in the last paragraph is false. At least for now. Turns out ansible's docker_service is just a wrapper around docker compose and that (very unfortunately) at the time of writing is not integrated with the docker swarm. Basically I'm out of luck here according to this support thread The same thread gives a possible workaround if you are interested

Bostone
  • 1,213
  • 2
  • 9
  • 8