---
# Tasks to install docker-registry
- name: install dependencies
  apt: name={{ item }} state=present update_cache=yes
  with_items:
    - build-essential
    - libevent-dev
    - libssl-dev
    - liblzma-dev
    - python-dev
    - python-pip

- name: install docker registry
  pip: name=docker-registry

- name: create required directories
  file: dest={{ item }} state=directory
  with_items:
    - "{{ storage_path }}"
    - /var/log/docker-registry
    - /etc/docker-registry

- name: set configuration file
  template: >
    src=config.yml.j2
    dest=/etc/docker-registry/config.yml
  notify: restart docker-registry

- name: create symlink for config
  file: >
    src=/etc/docker-registry/config.yml
    dest=/usr/local/lib/python2.7/dist-packages/config/config.yml
    state=link

- name: install docker-registry init file
  template: >
    src=docker-registry.init.j2
    dest=/etc/init/docker-registry.conf

- name: ensure docker registry is enabled and running
  service: name=docker-registry state=running enabled=yes

- include: redis.yml
  when: manage_redis

- include: nginx.yml
  when: manage_nginx

# Tests
# =====

# Required for uri module
- name: install httplib2 for tests
  pip: name=httplib2 state=present

# Ping the Docker registry, API documented here :
# https://docs.docker.com/reference/api/registry_api/
- name: ping docker registry
  uri: url=http://localhost:5000/v1/_ping method=GET follow_redirect=all return_content=yes status_code=200 timeout=3

---
# Tasks to install docker-registry
- name: install dependencies
  apt: name={{ item }} state=present update_cache=yes
  with_items:
    - build-essential
    - libevent-dev
    - libssl-dev
    - liblzma-dev
    - python-dev
    - python-pip

- name: install docker registry
  pip: name=docker-registry

- name: create required directories
  file: dest={{ item }} state=directory
  with_items:
    - "{{ storage_path }}"
    - /var/log/docker-registry
    - /etc/docker-registry

- name: set configuration file
  template: >
    src=config.yml.j2
    dest=/etc/docker-registry/config.yml
  notify: restart docker-registry

- name: create symlink for config
  file: >
    src=/etc/docker-registry/config.yml
    dest=/usr/local/lib/python2.7/dist-packages/config/config.yml
    state=link

- name: install docker-registry init file
  template: >
    src=docker-registry.init.j2
    dest=/etc/init/docker-registry.conf

- name: ensure docker registry is enabled and running
  service: name=docker-registry state=running enabled=yes

- include: redis.yml
  when: manage_redis

- include: nginx.yml
  when: manage_nginx

Remove ping test from role
Remove ping test from role
