---
# docker-compose/tasks/main.yml

# The following two tests are equivalent and both evaluate to 0 when
# `onos-cord-1` VM isn't set to be created, but the `equalto` test only exists
# in Jinja v2.7.4, which is later than what's in Ubuntu 14.04 (v2.7.2).
#
# {{ head_vm_list | selectattr('name', 'equalto', 'onos-cord-1') | list | length }}
# {{ head_vm_list | map(attribute='name') | list | intersect(['onos-cord-1']) | list | length }}

#- name: Wait for onos_setup_playbook to complete
#  when: "{{ head_vm_list | map(attribute='name') | list | intersect(['onos-cord-1']) | list | length }}"
#  async_status: jid={{ onos_setup_playbook.ansible_job_id }}
#  register: onos_setup_playbook_result
#  until: onos_setup_playbook_result.finished
#  delay: 10
#  retries: 120

#- name: Copy SSL Certs to ONOS so docker-compose can find it
#  when: "{{ head_vm_list | map(attribute='name') | list | intersect(['onos-cord-1']) | list | length }}"
#  command: ansible onos-cord-1 -u ubuntu -m copy \
#    -a "src=/usr/local/share/ca-certificates/cord_ca_cert.pem dest=~/cord/xos-certs.crt"

#- name: Build ONOS image with docker-compose
#  when: "{{ head_vm_list | map(attribute='name') | list | intersect(['onos-cord-1']) | list | length }}"
#  command: ansible onos-cord-1 -u ubuntu -m command \
#    -a "docker-compose build chdir=cord"

#- name: Start ONOS
#  when: "{{ head_vm_list | map(attribute='name') | list | intersect(['onos-cord-1']) | list | length }}"
#  command: ansible onos-cord-1:onos-fabric-1 -u ubuntu -m command \
#    -a "docker-compose up -d chdir=cord"

- name: Wait for test client to complete installation
  when: test_client_install is defined and test_client_install
  async_status: jid={{ test_client_playbook.ansible_job_id }}
  register: test_client_playbook_result
  until: test_client_playbook_result.finished
  delay: 10
  retries: 120

