How to run etcd cluster in docker using ansible?

I’m trying to run etcd cluster in docker via ansible.

I use docker_container ansible module and this is what I have:

  • Why can mysql CLI connect, but not WordPress?
  • SaltStack Caches installing package files and reproduce installation later
  • Ansible task timeout max length
  • using ansible for provisioning docker containers
  • Centos7 docker-py doesn't seem to be installed
  • Deployment of new version to containers
  • - name: Run etcd KV node
            name: "etcd0"
            network_mode: host
            command: [ "/usr/local/bin/etcd", \
            "-name etcd0", \
            "-advertise-client-urls http://{{ ansible_default_ipv4['address'] }}:2379,http://{{ ansible_default_ipv4['address'] }}:4001", \
            "-listen-client-urls,", \
            "-initial-advertise-peer-urls http://{{ ansible_default_ipv4['address'] }}:2380", \
            "-initial-cluster etcd0=http://{{ ansible_default_ipv4['address'] }}:2380", \
            "-initial-cluster-token etcd-cluster", \
            "-listen-peer-urls", \
            "-initial-cluster-state new" ]

    This work in single mode, but troubles come with more than 1 node because there is etcd parameter -initial-cluster which should contain all nodes, for example, in case of 3 nodes:

    -initial-cluster etcd0=,etcd1=,etcd2=

    I have no idea how to loop thru all nodes and build this string to run one docker container. Is it possible?

  • seccomp=unconfined for a container in a kubernetes pod? Or: changing default in docker 1.10?
  • jBPM-Workbench-Showcase docker image: internal git accessing/ clone function does not work
  • How can I tag a Docker image as I'm building it with stack?
  • Connect docker container to database in host's local network
  • Docker: Connecting to external database
  • Unable to find ssh key using phusion/base-image
  • One Solution collect form web for “How to run etcd cluster in docker using ansible?”

    hostvars magic variable at your service:

    - name: Generate useful facts for current node 1
        ip_addr: "{{ ansible_default_ipv4.address }}"
        etcd_name: "etcd{{ ansible_play_hosts.index(inventory_hostname) }}"
    - name: Generate useful facts for current node 2
        etcd_uri: "{{ etcd_name }}=http://{{ ip_addr }}:2380"
    - name: Run etcd KV node
        name: "{{ etcd_name }}"
        network_mode: host
          - /usr/local/bin/etcd
          - -name {{ etcd_name }}
          - -advertise-client-urls http://{{ ip_addr }}:2379,http://{{ ip_addr }}:4001
          - -listen-client-urls,
          - -initial-advertise-peer-urls http://{{ ip_addr }}:2380
          - -initial-cluster {{ ansible_play_hosts | map('extract',hostvars,'etcd_uri') | list | join(',') }}
          - -initial-cluster-token etcd-cluster
          - -listen-peer-urls
          - -initial-cluster-state new

    P.S. I also reformatted your command argument a bit.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.