---

#- name: (git.yml) include variables
#  include_vars: "{{ item }}"
#  with_first_found:
#    - "git-{{ inventory_hostname }}.yml"
#    - "git-{{ ansible_distribution_release }}.yml"
#    - "git-{{ ansible_distribution | lower }}.yml"
#    - git-default.yml
#  tags:
#    - git-default-repositories
#    - git-lxc-guest-repositories
#    - git-apache2-repositories
#    - git-nginx-repositories
#    - git-mysql-server-repositories
#    - git-postgresql-server-repositories
#    - git-nextcloud-server-repositories
#    - git-dns-server-repositories
#    - git-backup-server-repositories
#    - git-samba-server-repositories
#    - git-mailservers-repositories
#    - git-sympa-repositories
#    - git-other-repositories



# ---
#  Firewall repository
# ---

- name: (git.yml) Install/Update firewall repository
  git:
    repo: "{{  git_firewall_repository.repo }}"
    dest: "{{  git_firewall_repository.dest }}"
  when: git_firewall_repository is defined and git_firewall_repository | length > 0
  tags:
    - git-firewall-repository

# ---
#  Default reposotories
# ---

- name: (git.yml) Install/Update default repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_default_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  tags:
    - git-default-repositories


# ---
#  Group [oopen_server] reposotories
# ---

- name: (git.yml) Install/Update oopen_server repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_oopen_server_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['oopen_server']|string is search(inventory_hostname)"
  tags:
    - git-oopen-server-repositories


# ---
#  Group [warenform_server] reposotories
# ---

- name: (git.yml) Install/Update warenform_server repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_warenform_server_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['warenform_server']|string is search(inventory_hostname)"
  tags:
    - git-warenform-server-repositories


# ---
#  Group [lxc_guest] reposotories
# ---

- name: (git.yml) Install/Update lxc_guest repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_lxc_guest_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['lxc_guest']|string is search(inventory_hostname)"
  tags:
    - git-lxc-guest-repositories


# ---
#  Group [lxc_host] reposotories
# ---

- name: (git.yml) Install/Update lxc_host repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_lxc_host_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['lxc_host']|string is search(inventory_hostname)"
  tags:
    - git-lxc-host-repositories


# ---
#  Group [gateway_server] reposotories
# ---

- name: (git.yml) Install/Update gateway repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_gateway_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['gateway_server']|string is search(inventory_hostname)"
  tags:
    - git-gateway-server-repositories


# ---
#  Group [apache2_webserver] reposotories
# ---

- name: (git.yml) Install/Update apache2 repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_apache2_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['apache2_webserver']|string is search(inventory_hostname)"
  tags:
    - git-apache2-repositories


# ---
#  Group [nginx_webserver] reposotories
# ---

- name: (git.yml) Install/Update nginx repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_nginx_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['nginx_webserver']|string is search(inventory_hostname)"
  tags:
    - git-nginx-repositories


# ---
#  Group [mysql_server] reposotories
# ---

- name: (git.yml) Install/Update mysql server repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_mysql_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['mysql_server']|string is search(inventory_hostname)"
  tags:
    - git-mysql-server-repositories


# ---
#  Group [postgresql_server] reposotories
# ---

- name: (git.yml) Install/Update postgresql-server repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_postgresql_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['postgresql_server']|string is search(inventory_hostname)"
  tags:
    - git-postgresql-server-repositories


# ---
#  Group [nextcloud_server] reposotories
# ---

- name: (git.yml) Install/Update nextcloud server repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_nextcloud_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['nextcloud_server']|string is search(inventory_hostname)"
  tags:
    - git-nextcloud-server-repositories


# ---
#  Group [dns_server] reposotories
# ---

- name: (git.yml) Install/Update dns server repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_dns_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['dns_server']|string is search(inventory_hostname)"
  tags:
    - git-dns-server-repositories


# ---
#  Group [backup_server] reposotories
# ---

- name: (git.yml) Install/Update backup server repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_backup_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['backup_server']|string is search(inventory_hostname)"
  ignore_errors: True
  tags:
    - git-backup-server-repositories


# ---
#  Group [samba_server] reposotories
# ---

- name: (git.yml) Install/Update samba server repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_samba_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['samba_server']|string is search(inventory_hostname)"
  ignore_errors: True
  tags:
    - git-samba-server-repositories



# ---
#  Group [mail_server] reposotories
# ---

- name: (git.yml) Install/Update mail server repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_mailserver_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['mail_server']|string is search(inventory_hostname)"
  tags:
    - git-mailservers-repositories


# ---
#  Group [sympa_list_servers] reposotories
# ---

- name: (git.yml) Install/Update sympa server repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_sympa_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['sympa_list_server']|string is search(inventory_hostname)"
  tags:
    - git-sympa-repositories


# ---
#  Group [jitsi_meet_server] reposotories
# ---

- name: (git.yml) Install/Update sympa server repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  with_items: '{{ git_jitsi_meet_repositories }}'
  loop_control:
    label: "{{ item.name }}"
  when: "groups['jitsi_meet_server']|string is search(inventory_hostname)"
  tags:
    - git-jitsi_meet-repositories


# ---
#  Group [so36_server_dehydrated] reposotories
# ---

#- name: (git.yml) Install/Update sympa server repositories
#  git:
#    repo: '{{ item.repo }}'
#    dest: '{{ item.dest }}'
#  with_items: '{{ git_so36_dehydrated_repositories }}'
#  loop_control:
#    label: "{{ item.name }}"
#  when: "groups['so36_server_dehydrated']|string is search(inventory_hostname)"
#  tags:
#    - git-so36-dehydrated-repositories


# ---
#  Other (host specific) repositories
# ---

# Read in host specific vars file if exists
- name: (git.yml) Include only files matching git-<hostname>.yml (2.2)
  include_vars:
    dir: vars
    extensions:
      - yml
    files_matching: "git-{{ inventory_hostname }}.yml"
  tags:
    - git-other-repositories

- name: (git.yml) Install/Update other repositories
  git:
    repo: '{{ item.repo }}'
    dest: '{{ item.dest }}'
  loop_control:
    label: "{{ item.name }}"
  with_items: '{{ git_other_repositories }}'
  tags:
    - git-other-repositories
