Created
October 22, 2015 18:58
-
-
Save jcpowermac/08d8591015e9e3dbdb14 to your computer and use it in GitHub Desktop.
Ansible Hanlon Docker with Consul and Registrator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - name: Start Hanlon Docker Environment | |
| hosts: localhost | |
| vars: | |
| hanlon_resource: "/opt/hanlon" | |
| docker_network: "{{ ansible_docker0.ipv4.network }}" | |
| local_network: "{{ ansible_default_ipv4.network }}" | |
| hanlon_subnets: "{{ local_network }}/24,{{ docker_network }}/16" | |
| docker_api_version: 1.18 | |
| tasks: | |
| - name: Ansible Docker Requirements | |
| pip: | |
| name: "{{ item }}" | |
| extra_args: "-I" | |
| with_items: | |
| - six==1.4.1 | |
| - docker-py==1.1.0 | |
| - requests==2.7.0 | |
| - name: Clean up existing containers | |
| docker: | |
| docker_api_version: "{{ docker_api_version }}" | |
| name: "{{ item.name }}" | |
| image: "{{ item.image }}" | |
| state: absent | |
| with_items: | |
| # - { name: hanlon-mongo, image: mongo } | |
| - { name: hanlon-consul, image: gliberlabs/consul-server } | |
| - { name: hanlon-registrator, image: gliderlabs/registrator } | |
| - { name: hanlon-cassandra, image: tobert/cassandra } | |
| - { name: hanlon-server, image: cscdock/hanlon } | |
| - { name: hanlon-atftpd, image: cscdock/atftpd } | |
| - name: Consul | |
| docker: | |
| docker_api_version: "{{ docker_api_version }}" | |
| name: hanlon-consul | |
| image: gliderlabs/consul-server | |
| pull: always | |
| ports: | |
| - 10.66.1.1:8500:8500 | |
| - 10.53.252.50:53:8600/udp | |
| - 10.53.252.50:8500:8500 | |
| - 8400:8400 | |
| command: "-node myconsul -bootstrap -advertise 10.53.252.50 -client 0.0.0.0" | |
| - name: registrator | |
| docker: | |
| docker_api_version: "{{ docker_api_version }}" | |
| name: hanlon-registrator | |
| image: gliderlabs/registrator | |
| pull: always | |
| volumes: | |
| - /var/run/docker.sock:/tmp/docker.sock | |
| command: "consul://10.66.1.1:8500" | |
| privileged: true | |
| # - name: Start Mongo Container | |
| # docker: | |
| # docker_api_version: "{{ docker_api_version }}" | |
| # name: hanlon-mongo | |
| # image: mongo | |
| # pull: always | |
| # state: started | |
| # command: mongod --smallfiles | |
| # volumes: "{{ hanlon_resource }}/data/db:/data/db" | |
| - name: Start Cassandra Container | |
| docker: | |
| docker_api_version: "{{ docker_api_version }}" | |
| name: hanlon-cassandra | |
| image: tobert/cassandra | |
| pull: always | |
| state: started | |
| volumes: "{{ hanlon_resource }}/data/db:/data" | |
| - name: Wait for Cassandra Server to start | |
| command: docker exec hanlon-cassandra nodetool info | |
| register: result | |
| until: result.rc == 0 | |
| retries: 3 | |
| delay: 10 | |
| - name: Remove hanlon client config file | |
| file: | |
| path: "{{ hanlon_resource }}/cli/config/hanlon_client.conf" | |
| state: absent | |
| - name: Start Hanlon Server Container | |
| docker: | |
| docker_api_version: "{{ docker_api_version }}" | |
| name: hanlon-server | |
| image: cscdock/hanlon | |
| pull: always | |
| state: started | |
| ports: 10.53.252.50:8026:8026 | |
| dns: | |
| - "10.53.252.50" | |
| - "8.8.8.8" | |
| links: hanlon-cassandra:cassandra | |
| # links: hanlon-mongo:mongo | |
| privileged: true | |
| volumes: | |
| - "{{ hanlon_resource }}/image:/home/hanlon/image" | |
| - "{{ hanlon_resource }}/cli/config:/home/hanlon/cli/config" | |
| env: | |
| DOCKER_HOST: "{{ ansible_default_ipv4.address }}" | |
| HANLON_SUBNETS: "{{ hanlon_subnets }}" | |
| # Needed for Cassandra | |
| PERSIST_MODE: "@cassandra" | |
| REPL_STRATEGY: "SimpleStrategy" | |
| REPL_FACTOR: "1" | |
| - name: Start Hanlon Server Container | |
| docker: | |
| docker_api_version: "{{ docker_api_version }}" | |
| name: hanlon-server-b | |
| image: cscdock/hanlon | |
| pull: always | |
| state: started | |
| dns: | |
| - "10.53.252.50" | |
| - "8.8.8.8" | |
| ports: 10.53.252.51:8026:8026 | |
| links: hanlon-cassandra:cassandra | |
| # links: hanlon-mongo:mongo | |
| privileged: true | |
| volumes: | |
| - "{{ hanlon_resource }}/image:/home/hanlon/image" | |
| - "{{ hanlon_resource }}/cli/config:/home/hanlon/cli/config" | |
| env: | |
| DOCKER_HOST: "{{ ansible_default_ipv4.address }}" | |
| HANLON_SUBNETS: "{{ hanlon_subnets }}" | |
| # Needed for Cassandra | |
| PERSIST_MODE: "@cassandra" | |
| REPL_STRATEGY: "SimpleStrategy" | |
| REPL_FACTOR: "1" | |
| - name: Wait for Hanlon Server to start | |
| tags: ipxe_wait | |
| uri: url=http://{{ ansible_default_ipv4.address }}:8026/hanlon/api/v1/config/ipxe return_content=yes | |
| register: return | |
| until: (return.content.find("#!ipxe") != -1) and (return.content is defined) | |
| - name: Start TFTP Server Container | |
| docker: | |
| docker_api_version: "{{ docker_api_version }}" | |
| name: hanlon-atftpd | |
| image: atftpd | |
| pull: missing | |
| state: started | |
| ports: 69:69/udp | |
| links: hanlon-server:hanlon | |
| privileged: true | |
| net: host |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment