---

### tags:
###   harbor-configure-system
###   harbor-configure-robots

- name: "Check if harbor is up and running"
  delegate_to: 127.0.0.1
  become: false
  uri:
    url: "{{ shared_service_url_harbor }}/api/v2.0/configurations"
    user: '{{ harbor_admin_username }}'
    password: '{{ harbor_admin_password }}'
    method: GET
    body_format: json
    force_basic_auth: yes
    status_code: [200]
  register: check_harbor
  delay: 10
  retries: 20
  until: check_harbor.status in [200]

- name: "Configure harbor system configurations"
  include_tasks: configure-system.yml
  args:
   apply:
      tags:
        - harbor-configure-system
  tags:
    - harbor-configure-system

- name: "Create harbor projects with project template"
  set_fact:
    harbor_projects: "{{ ( harbor_projects | default([]) ) + [ harbor_project_template ] }}"
  loop: '{{ harbor_project_names }}'
  loop_control:
    loop_var: project_name
  when:
    - harbor_project_names is defined

- name: "Update harbor projects"
  include_tasks: configure_project.yml
  loop: '{{ harbor_projects }}'
  loop_control:
    loop_var: project

- name: "CRUD - robot tokens"
  include_tasks: configure_robot_tokens.yml
  loop: '{{ harbor_robot_tokens }}'
  loop_control:
    loop_var: robot_token
  tags:
    - harbor-configure-robots

- name: "CRUD - scanall schedule"
  include_tasks: configure_scanall_schedule.yml
  loop: '{{ harbor_scanall }}'
  loop_control:
    loop_var: scanschedule
