Using the Ansible docker_service module to deploy a service for a swarm

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

Here is my setup:

I have 3 node Docker (v.1.12.1) swarm, which includes one host working as a manager, and two work nodes, all of which work in CentOS 7. On the manager node (localhost) launched Ansible (v. 2.1.1.0) playbook, and the swarm is already configured and working

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 tutorial having 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 }

What causes 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 start ansible-playbook ./site.yml, I end up with a running container. Execution docker ps -adisplays

[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

docker service ls , , docker_service ,

, , , , Ansible docker_service, . , , , .., , . , , !

+4
3

Ansible module Docker Compose, Swarm Mode. docker-compose node , docker run, , , , Swarm.

Compose issue 3656, , Ansible ( Compose , ).

+2

, , Ansible . , 100% , . git Docker. .

+2

, 1.12, -, - . , "" , , : https://docs.docker.com/swarm/install-w-machine/ (Nota: consul)

docker-service , : DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH,...

, .

- , :

  docker-machine env --swarm <swarm_marster>

, , ( echo $DOCKER_HOST -?).

enrivonment ( ):

  - 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}}"
      docker_host: tcp://192.168.1.1:2376
      tls_verify: 1

    register: output
  - debug: var=output

DOCKER_CERT_PATH, : tls_ca_cert, tls_client_cert tls_client_key

0

Source: https://habr.com/ru/post/1657101/


All Articles