├── hosts ├── README.md ├── compose ├── helloworld │ └── Dockerfile ├── nginx │ └── conf.d │ │ └── helloworld.conf └── docker-compose.yml ├── helloworld └── app.py └── provision.yml /hosts: -------------------------------------------------------------------------------- 1 | [localhost] 2 | 127.0.0.1 3 | # ansible_python_interpreter=/usr/bin/python2.7 4 | 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Synopsis 2 | 3 | This is just an example of how to run docker-compose (v2) project 4 | using ansible docker_service module 5 | https://docs.ansible.com/ansible/docker_service_module.html 6 | 7 | The docker-compose / project is from 8 | https://docs.ansible.com/ansible/docker_service_module.html 9 | 10 | -------------------------------------------------------------------------------- /compose/helloworld/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | MAINTAINER Your Name 3 | 4 | ENV HOME /root 5 | ENV DEBIAN_FRONTEND noninteractive 6 | 7 | RUN apt-get -yqq update 8 | RUN apt-get install -yqq python python-dev python-pip 9 | RUN pip install pyramid 10 | 11 | WORKDIR /code 12 | CMD ["python", "app.py"] 13 | -------------------------------------------------------------------------------- /compose/nginx/conf.d/helloworld.conf: -------------------------------------------------------------------------------- 1 | server { 2 | 3 | listen 80; 4 | server_name helloworld.org; 5 | charset utf-8; 6 | 7 | location / { 8 | proxy_pass http://helloworld:5000; 9 | proxy_set_header Host $host; 10 | proxy_set_header X-Real-IP $remote_addr; 11 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /compose/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | helloworld: 4 | build: ./helloworld 5 | image: helloworld:1.0 6 | volumes: 7 | - ../helloworld:/code 8 | - ./logs:/var/log 9 | - ./config:/etc/appconfig 10 | 11 | nginx: 12 | image: nginx:alpine 13 | ports: 14 | - "80:80" 15 | volumes: 16 | - ./nginx/conf.d:/etc/nginx/conf.d 17 | links: 18 | - helloworld 19 | -------------------------------------------------------------------------------- /helloworld/app.py: -------------------------------------------------------------------------------- 1 | from wsgiref.simple_server import make_server 2 | from pyramid.config import Configurator 3 | from pyramid.response import Response 4 | 5 | 6 | def hello_world(request): 7 | print('Incoming request') 8 | return Response('

Hello World!

') 9 | 10 | 11 | if __name__ == '__main__': 12 | config = Configurator() 13 | config.add_route('hello', '/') 14 | config.add_view(hello_world, route_name='hello') 15 | app = config.make_wsgi_app() 16 | server = make_server('0.0.0.0', 5000, app) 17 | server.serve_forever() 18 | -------------------------------------------------------------------------------- /provision.yml: -------------------------------------------------------------------------------- 1 | - name: Run using a project directory 2 | hosts: localhost 3 | connection: local 4 | gather_facts: no 5 | tasks: 6 | - docker_service: 7 | project_src: compose 8 | state: absent 9 | 10 | - docker_service: 11 | project_src: compose 12 | register: output 13 | 14 | - debug: 15 | var: output 16 | 17 | - docker_service: 18 | project_src: compose 19 | build: no 20 | register: output 21 | 22 | - debug: 23 | var: output 24 | 25 | - assert: 26 | that: "not output.changed " 27 | 28 | - docker_service: 29 | project_src: compose 30 | build: no 31 | stopped: true 32 | register: output 33 | 34 | - debug: 35 | var: output 36 | 37 | - assert: 38 | that: 39 | - "not helloworld.compose_helloworld_1.state.running" 40 | 41 | - docker_service: 42 | project_src: compose 43 | build: no 44 | restarted: true 45 | register: output 46 | 47 | - debug: 48 | var: output 49 | 50 | - assert: 51 | that: 52 | - "helloworld.compose_helloworld_1.state.running" 53 | 54 | --------------------------------------------------------------------------------