---
# juju-finish/tasks/main.yml

# run another time, so services will be in juju_services list
- name: Obtain Juju Facts after service creation
  juju_facts:
  register: result
  until: result | success
  retries: 3
  delay: 15

# 1800s = 30m. Usually takes 10-12m on cloudlab for relations to come up
# Only checks for first port in list
- name: Wait for juju services to have open ports
  wait_for:
    host={{ item.name }}
    port={{ item.forwarded_ports[0].int }}
    timeout=1800
  with_items: "{{ head_lxd_list | selectattr('forwarded_ports', 'defined') | list }}"

# secondary wait, as waiting on ports isn't enough. Probably only need one of these...
# 160*15s = 2400s = 40m max wait
- name: Wait for juju services to start
  command: juju status --format=summary
  register: juju_summary
  until: juju_summary.stdout.find("pending:") == -1
  retries: 160
  delay: 15
  tags:
   - skip_ansible_lint # checking/waiting on a system to be up

- name: Create admin-openrc.sh credentials file
  template:
   src=admin-openrc.sh.j2
   dest={{ ansible_user_dir }}/admin-openrc.sh

